I thought the below is logically sound in adding or inserting object into an object array but the result I am getting is funky. Can someone please tell me what I am doing wrong here?? Why is below code returning empty array when I am trying to insert an object into an object array in the index of 0 and why is below code returning 4 when I am trying to add an object at the end of the object array?
let objArr = [{
id: 1,
company: "Rapid Precision Mfg.",
title: "Quality Engineer",
firstName: "Dongyob",
lastName: "Lee",
officePh: "",
ext: "",
cell: "669-294-0910",
email: "[email protected]"
},
{
id: 2,
company: "Facebook",
title: "Frontend Developer",
firstName: "Edward",
lastName: "Simmons",
officePh: "408-516-4662",
ext: "003",
cell: "669-252-4251",
email: "[email protected]"
}
]
let nobj = {
id: 1,
company: "Rapid Precision Mfg.",
title: "Quality Engineer",
firstName: "Dongyob",
lastName: "Lee",
officePh: "",
ext: "",
cell: "669-294-0910",
email: "[email protected]"
}
console.log(objArr.splice(0, 0, nobj)) //Outcome: []
console.log(objArr.push(nobj)) //Outcome: 4