I have the solution but Is there any other nicer way to do in javascript or is it possible to modify the arr1 itself and have arr1 as array of objects alone
I have array of objects and string
arr1 = [{
id: 'id1',
name: 'name1'
}, {
id: 'id2',
name: 'name2'
}, '/roll', '/roll1'];
i would like to have array of objects alone at the end
newarr1 = [{
id: "id1",
name: "name1"
}, {
id: "id2",
name: "name2"
}]
current solution
arr1.map((item) => {
if (typeof item === 'object') return newarr1.push(item)
})
let newArr1 = []; arr1.forEach((item) => { if (typeof item === 'object') newarr1.push(item); });