Im trying to sort the name of the link alphabetically, but it says level2.sort is not a function any help is appreciated!
for (let i = 0, l = finalData.length; i < l; i++) {
const level1 = finalData[i];
console.log('This is level 1', level1);
for (let x = 0, y = finalData[i].links.length; x < y; x++) {
const level2 = finalData[i].links[x];
level2.sort((a, b) => a.name - b.name);
console.log('This is level 2', level2);
}
}
Level 1 at [0] is {title: "resources" , links:Array(3)}
Level 2 at [0] is {name: "google", path:"www.google.com"}
Level 2 at [1] is {name: "yahoo", path:"www.yahoo.com"}
Level 2 at [2] is {name: "apple", path:"www.apple.com"}
Level 1 at [1] is {title: "TeacherEmails" , links:Array(2)}
Level 2 at [0] is {name: "JoneA", path:"[email protected]"}
Level 2 at [1] is {name: "AndyK", path:"[email protected]"}
and so on
console.logs ? level2 seems to not be an array but an object