How to extract a property from array of objects and slice it?

Somethingwhatever

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.

Finnnn

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]

編集
0

コメントを追加

0

関連記事

分類Dev

Lumen/Laravel - Method to extract specific property from objects in an array of objects?

分類Dev

Extract bits into a int slice from byte slice

分類Dev

How to extract array from $_POST

分類Dev

Javascript: extract objects from inside an array of objects, and put them into a new array

分類Dev

How can I slice out all of the array objects containing a value and storing them in a new array

分類Dev

javascript return property value from nested array of objects based on condition

分類Dev

Fetch unique values from array of objects based on dynamically passed property

分類Dev

How to get unique an array of objects back from a complex an array of objects?

分類Dev

How to sort an array of objects by property value in Angular with custom pipe?

分類Dev

How to remove duplicates objects from array in javascript?

分類Dev

How to get an Array of Objects from Firestore in Swift?

分類Dev

How to put values of objects from an array into a string

分類Dev

Extract Property value from NodeList

分類Dev

How to rank objects by property?

分類Dev

Sort array of objects by property length

分類Dev

Obtain one property of an array of objects

分類Dev

JPA How to get a property from a Arraylist of objects in a ManyToMany relation

分類Dev

How to display same property from different objects in Javascript

分類Dev

How do I loop over an array of objects to return a property dependent on a corresponding property within that object?

分類Dev

How to filter an array that excludes from object's property array

分類Dev

How to get a particular attribute from an array of array objects?

分類Dev

How to get the combination of array values from nested arrays in an array of objects

分類Dev

How to change json data format from array to array of objects with javascript?

分類Dev

JS filtering array in object property of array of objects

分類Dev

Jmeter : How to extract first element from json array

分類Dev

How do I extract a specific object from a nested array?

分類Dev

How to extract only the image path from the array I'm getting?

分類Dev

Extract child objects into array inside MongoDB aggregation

分類Dev

T-SQL: How Can I Parse a JSON Array and Extract a Single Property Value?

Related 関連記事

  1. 1

    Lumen/Laravel - Method to extract specific property from objects in an array of objects?

  2. 2

    Extract bits into a int slice from byte slice

  3. 3

    How to extract array from $_POST

  4. 4

    Javascript: extract objects from inside an array of objects, and put them into a new array

  5. 5

    How can I slice out all of the array objects containing a value and storing them in a new array

  6. 6

    javascript return property value from nested array of objects based on condition

  7. 7

    Fetch unique values from array of objects based on dynamically passed property

  8. 8

    How to get unique an array of objects back from a complex an array of objects?

  9. 9

    How to sort an array of objects by property value in Angular with custom pipe?

  10. 10

    How to remove duplicates objects from array in javascript?

  11. 11

    How to get an Array of Objects from Firestore in Swift?

  12. 12

    How to put values of objects from an array into a string

  13. 13

    Extract Property value from NodeList

  14. 14

    How to rank objects by property?

  15. 15

    Sort array of objects by property length

  16. 16

    Obtain one property of an array of objects

  17. 17

    JPA How to get a property from a Arraylist of objects in a ManyToMany relation

  18. 18

    How to display same property from different objects in Javascript

  19. 19

    How do I loop over an array of objects to return a property dependent on a corresponding property within that object?

  20. 20

    How to filter an array that excludes from object's property array

  21. 21

    How to get a particular attribute from an array of array objects?

  22. 22

    How to get the combination of array values from nested arrays in an array of objects

  23. 23

    How to change json data format from array to array of objects with javascript?

  24. 24

    JS filtering array in object property of array of objects

  25. 25

    Jmeter : How to extract first element from json array

  26. 26

    How do I extract a specific object from a nested array?

  27. 27

    How to extract only the image path from the array I'm getting?

  28. 28

    Extract child objects into array inside MongoDB aggregation

  29. 29

    T-SQL: How Can I Parse a JSON Array and Extract a Single Property Value?

ホットタグ

アーカイブ