This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
8
Using function parameters to specify object property
Post Body
EDIT: Solved using the notation "array[i][property]". Thanks to u/jrandm for the help!
First time posting here, so hi everyone! I'm trying to write a reusable function that searches an array for an object with a certain property. Probably makes more sense to just show you the code:
genSearch = function(array, property, value) {
let searchResults = [];
for (i = 0; i < array.length; i ) {
if (array[i].(property) == value)
searchResults.push(array[i]);
}
return searchResults;
}
The problem is on the 4th line. An identifier is expected after "array[i]." and I was hoping I could just plug in "property" there, but it seems I can't. Is there some way to use a function parameter like this?
Author
Account Strength
90%
Account Age
7 years
Verified Email
Yes
Verified Flair
No
Total Karma
588
Link Karma
235
Comment Karma
353
Profile updated: 5 days ago
Posts updated: 2 months ago
Subreddit
Post Details
We try to extract some basic information from the post title. This is not
always successful or accurate, please use your best judgement and compare
these values to the post title and body for confirmation.
- Posted
- 4 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnjavasc...