so i have an array of objects which returns phoneNumber and businessNumber and name. I am trying to extract the businessNumber and phoneNumber and want to slice them from \"-\"
you could return both numbers in an array of new objects
let arr1 = myArray.map(function(obj) {
return {
businessNumber: obj.businessNumber.split('-').pop(),
phoneNumber: obj.phoneNumber.split('-').pop()
}
})
You could do something like this if you change your map function slightly.
myArray = [{
phoneNumber: "(111) 222-3344",
businessNumber: "(112) 333-4567",
name: "Name1"
},
{
phoneNumber: "(111) 222-3344",
businessNumber: "(112) 333-4567",
name: "Name1"
},
{
phoneNumber: "(111) 222-3344",
businessNumber: "(112) 333-4567",
name: "Name1"
},
{
phoneNumber: "(111) 222-3344",
businessNumber: "(112) 333-4567",
name: "Name1"
},
]
let updatedArr = myArray.map((obj) => {
obj.phoneNumber = obj.phoneNumber.split('-').pop()
obj.businessNumber = obj.businessNumber.split('-').pop()
return(obj);
})
console.log(updatedArr)