The name attribute_name:"position"
is very rare and I want to check that if the property exists I want to push it to the new array. However, every time I try to add a condition it gives me errors.
[0].attribute_name
inside the for
loop is giving me trouble. There may or may not be two arrays inside activity_attributes
. But I want to make a call bases on first array, if the itemloop[i].activity_attributes[0].attribute_name
push them to new array.
if(res.status == "success") {
var itemloop = res.response.activities;
var social_post_link = [];
for(var i=0; i<itemloop.length; i++){
if(itemloop[i].activity_attributes[0].attribute_name == "position") {
social_post_link.push(itemloop[i].activity_attributes);
}
}
console.log(social_post_link);
}