Is there any function in jQuery that is equivalent to PHP's array_column()?

前端 未结 6 1343
轻奢々
轻奢々 2021-02-10 04:57

What is the equivalent to PHP\'s array_column() in jQuery? I need the data inside the array without looping, in the same way as in PHP.

6条回答
  •  爱一瞬间的悲伤
    2021-02-10 05:48

    Shorter version of Fabian's answer using arrow notation:

    let array = [
        {
            id: 1,
            name: 'foo'
        },
        {
            id: 2,
            name: 'bar'
        },
    ];
    
    let names = array.map( el => el.name );
    

提交回复
热议问题