Hi there I am adding the string 'a ' to the beginning of the value of name. I have also added a condition where if the value of name.length === 3, then add the string 'a ' but it is only returning the objects that get changed and only the name property.
var values1 = [
{
name: 'dog',
surname: 'good',
skills: 'programming',
},
{
name: 'cat',
surname: 'soft',
skills: 'engineer',
},
{
name: 'elephant',
surname: 'big',
skills: 'programming',
},
];
let array = [];
for (let i = 0; i < values1.length; i++) {
if (values1[i]['name'].length == 3) {
array.push({ name: 'a ' + values1[i]['name'] });
}
}
for (let i = 0; i < array.length; i++) {
console.log(array[i]);
}
This is the result I would like to return.
[
{
name: 'a dog',
surname: 'good',
skills: 'programming',
},
{
name: 'a cat',
surname: 'soft',
skills: 'engineer',
},
{
name: 'elephant',
surname: 'big',
skills: 'programming',
},
];
array.push({ name: 'a ' + values1[i]['name'] });