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 "-" to only show the last 4 digits?
I was able to use the map to extract the businessNumber but how can i split an return them both in the desired format?
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 arr1 = myArray.map(function(obj) {
return obj.businessNumber.split('-').pop()
})
console.log(arr1)
Thank you in advance.
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()
}
})
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加