代码之家  ›  专栏  ›  技术社区  ›  Deji Akinbode

返回对象getaccountfullname数组中的名字和姓氏的Javascript

  •  -1
  • Deji Akinbode  · 技术社区  · 2 年前

    const accounts = [
      {
        id: "5f446f2ecfaf0310387c9603",
        picture: "https://api.adorable.io/avatars/75/[email protected]",
        age: 25,
        name: {
          first: "Esther",
          last: "Tucker",
        },
        company: "ZILLACON",
        email: "[email protected]",
        registered: "Thursday, May 28, 2015 2:51 PM",
      },
      {
        id: "5f446f2ed46724f41c9fc431",
        picture: "https://api.adorable.io/avatars/75/[email protected]",
        age: 35,
        name: {
          first: "Ferrell",
          last: "Morris",
        },
        company: "ECOLIGHT",
        email: "[email protected]",
        registered: "Thursday, February 8, 2018 1:16 PM",
      }]
    
    function getAccountFullNames(accounts) {
    
     
    }
    
    return accounts.name.first + account.name.last

    埃丝特·塔克的回报是什么

    1 回复  |  直到 2 年前
        1
  •  0
  •   Alexander Nenashev    2 年前

    使用 Array::map() 和对数组项参数进行对象析构函数:

    function getAccountFullNames(accounts) {
      return accounts.map(({name:{first, last}}) => first + ' ' + last);
    }
    
    console.log(getAccountFullNames(accounts));
    <script>
    const accounts = [ { id: "5f446f2ecfaf0310387c9603", picture: "https://api.adorable.io/avatars/75/[email protected]", age: 25, name: { first: "Esther", last: "Tucker", }, company: "ZILLACON", email: "[email protected]", registered: "Thursday, May 28, 2015 2:51 PM", }, { id: "5f446f2ed46724f41c9fc431", picture: "https://api.adorable.io/avatars/75/[email protected]", age: 35, name: { first: "Ferrell", last: "Morris", }, company: "ECOLIGHT", email: "[email protected]", registered: "Thursday, February 8, 2018 1:16 PM", }]
    
    </script>