第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

從另一個(gè)數(shù)組在 JavaScript 中創(chuàng)建新的對象數(shù)組

從另一個(gè)數(shù)組在 JavaScript 中創(chuàng)建新的對象數(shù)組

幕布斯7119047 2023-06-15 10:04:00
從一個(gè)對象數(shù)組,我需要?jiǎng)?chuàng)建另一個(gè)包含一些字段的對象數(shù)組。在我的 organicResults 數(shù)組中,我有以下項(xiàng)目我只需要新數(shù)組中的標(biāo)題和 url。我嘗試了以下 const organicResults = [ {      title: '21 Excel Tips and Tricks to Boost Business | Process Street ...',      url: 'https://www.process.st/excel-tips-and-tricks/',      displayedUrl: 'www.process.st ? excel-tips-and-tricks',      description: 'Mar 10, 2017 — 90% of businesses use Excel in their operations. Learn these Excel tips and tricks to maximize your efficiency and automate your processes!',      siteLinks: [],      productInfo: {}    },    {      title: 'Microsoft Excel Tips & Tricks | The Training Lady',      url: 'https://www.thetraininglady.com/microsoft-excel/',      displayedUrl: 'www.thetraininglady.com ? microsoft-excel',      description: 'When you are entering data in Excel you may want to ensure your data is entered in a consistent way. Maybe you have multiple people working on the same file ...',      siteLinks: [],      productInfo: {}    },    {      title: 'What are the best Microsoft Excel tips according to you? - Quora',      url: 'https://www.quora.com/What-are-the-best-Microsoft-Excel-tips-according-to-you',      displayedUrl: 'www.quora.com ? What-are-the-best-Microsoft-Excel-tips...',      description: 'Originally Answered: What is the best microsoft excel tip according to you? Below is a listing of all the major shortcut keys usable in Microsoft Excel.64 answers',      siteLinks: [],      productInfo: {}    },]    let sitesInfo = organicResults.map(result => ({        title: result.title,        url : result.url,        description: result.description            }))    console.log(sitesInfo)輸出為空。我哪里做錯(cuò)了?
查看完整描述

4 回答

?
函數(shù)式編程

TA貢獻(xiàn)1807條經(jīng)驗(yàn) 獲得超9個(gè)贊

您的代碼工作正常。讓我展示一個(gè)較短的版本,您可以在其中聲明所需的屬性:


let sitesInfo = organicResults.map(({title, url, description}) => 

    ({title, url ,description}))

一個(gè)例子:


const organicResults = [ {

      title: '21 Excel Tips and Tricks to Boost Business | Process Street ...',

      url: 'https://www.process.st/excel-tips-and-tricks/',

      displayedUrl: 'www.process.st ? excel-tips-and-tricks',

      description: 'Mar 10, 2017 — 90% of businesses use Excel in their operations. Learn these Excel tips and tricks to maximize your efficiency and automate your processes!',

      siteLinks: [],

      productInfo: {}

    },

    {

      title: 'Microsoft Excel Tips & Tricks | The Training Lady',

      url: 'https://www.thetraininglady.com/microsoft-excel/',

      displayedUrl: 'www.thetraininglady.com ? microsoft-excel',

      description: 'When you are entering data in Excel you may want to ensure your data is entered in a consistent way. Maybe you have multiple people working on the same file ...',

      siteLinks: [],

      productInfo: {}

    },

    {

      title: 'What are the best Microsoft Excel tips according to you? - Quora',

      url: 'https://www.quora.com/What-are-the-best-Microsoft-Excel-tips-according-to-you',

      displayedUrl: 'www.quora.com ? What-are-the-best-Microsoft-Excel-tips...',

      description: 'Originally Answered: What is the best microsoft excel tip according to you? Below is a listing of all the major shortcut keys usable in Microsoft Excel.64 answers',

      siteLinks: [],

      productInfo: {}

    },

]


    let sitesInfo = organicResults.map(({title, url, description}) => 

        ({title, url , description}))

    console.log(sitesInfo)


查看完整回答
反對 回復(fù) 2023-06-15
?
HUH函數(shù)

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超4個(gè)贊

檢查您的括號中的地圖方法..


let sitesInfo = organicResults.map(result => {

  return {

    title: result.title,

    url : result.url,

    description: result.description

  }

})


查看完整回答
反對 回復(fù) 2023-06-15
?
largeQ

TA貢獻(xiàn)2039條經(jīng)驗(yàn) 獲得超8個(gè)贊

使用常規(guī)函數(shù)仍然更安全。


let sitesInfo = organicResults.map(function(el) {

  return {title: el.title, url: el.url, description: el.description}

})


查看完整回答
反對 回復(fù) 2023-06-15
?
慕少森

TA貢獻(xiàn)2019條經(jīng)驗(yàn) 獲得超9個(gè)贊

你需要使用return


將其插入 sitesInfo 部分


var sitesInfo = organicResults.map(results => {

var object = {

        title: result.title,

        url : result.url,

        description: result.description

    }

    return object;

});

console.log(sitesInfo)

告訴我這對你有用嗎!:)


查看完整回答
反對 回復(fù) 2023-06-15
  • 4 回答
  • 0 關(guān)注
  • 178 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號