JSFiddle - React, Tailwind, and code Playground
by Arif Hasan
JavaScript
function Person(name, age, friends) {
this.name = name;
this.age = age;
this.friends = friends;
};
var john = new Person('john', 28, [new Person('elsa', 29, []), new Person('kevin', 31, [])]);
for (var i = 0; i < john.friends.length; i++) {
var friendName = john.friends[i].name;
}
// alert(friendName);
var friendNames = []; // store their names within a local array
for(var i = 0; i < john.friends.length; i++){
friendNames.push(john.friends[i].name);
}
console.log(friendNames);