I'm new to coding and have been working on some example problems for practice...
For this question I was to to create an array of objects for 10 employees and assign them name, age, position, and salary. Then, I was to find the salaries of all developers. I was able to do this but, I was wondering how to then convert the salaries to an array.
Code and what it displays in the console below:
const people = [
{name: "bob", age: 20, position: "developer", salary: 120_000},
{name: "susy", age: 26, position: "designer", salary: 140_000},
{name: "peter", age: 33, position: "developer", salary: 220_000},
{name: "cody", age: 51, position: "boss", salary: 400_000},
{name: "franklin", age: 22, position: "designer", salary: 150_000},
{name: "anna", age: 27, position: "developer", salary: 175_000},
{name: "justin", age: 35, position: "developer", salary: 230_000},
{name: "charlie", age: 23, position: "designer", salary: 120_000},
{name: "tony", age: 38, position: "designer", salary: 210_000},
{name: "ruth", age: 41, position: "developer", salary: 300_000}
];
function displayDeveloperSalaries(array){
const developers = people.filter(person => person.position === "developer");
for (let i = 0; i < developers.length; i++) {
console.log(developers[i].salary);
}
}
displayDeveloperSalaries(people);
120000
220000
175000
230000
300000
Any help is much appreciated. Thanks!
Not exactly how to convert the returned values to an array... I was able to push the values each to their own array like this,
[ 120000 ]
[ 220000 ]
[ 175000 ]
[ 230000 ]
[ 300000 ]
but I'm not sure how to concat these into a new array or what the best method is.