Say I had
var people =[{name:"Jim", address:{number:"21",street:"park lane"}},
{name:"Karen",address:{number:"35", street:"oxford drive"}},
{name:"Bob",address:{number:65, street:"main avenue"}}]
and I wanted to get an array of just the address objects, is there a shorthand way?
I know I could just iterate over the people array and push the addresses onto a new array, but I imagine there must be an easier way.
Maybe this:
people.map(function(x){return x.address;});
You are still iterating, but it is more concise.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다