亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將單詞從對象打印到javascript中的指定位置

如何將單詞從對象打印到javascript中的指定位置

白衣非少年 2021-04-09 18:15:47
我在javascript中有對象,對象的鍵是我的段落中的單詞,如何在段落中打印它.Value(key:value)保持其位置。嘗試使用for循環獲取對我不起作用var userdata= {          "\"Ten": [            0          ],          "blue": [            1          ],          "links\"": [            2          ],          "have": [            3          ],          "defined": [            4          ],          "web": [            5,            36,            65          ],          "search": [            6,            32,            37,            70,            90,            108,            126          ],          "results": [            7,            33,            38,            71,            82,            99,            119          ],          "for": [            8,            80          ],          "the": [            9,            28,            56,            61,            69,            95,            105          ],          "last": [            10          ],          "fifteen": [            11          ],          "years": [            12          ],          "--": [            13          ],          "snippets": [            14          ],          "of": [            15,            30,            63,            97,            107,            125          ],        };“十個藍色鏈接”定義了過去十五年的網絡搜索結果-文本片段以及文檔標題和URL。在本文中,我們建立了增強搜索結果的概念,將Web搜索結果擴展到包括圖像和視頻之類的多媒體對象,特定于意圖的鍵值對以及允許用戶直接與網頁內容進行交互的元素從搜索結果頁面。我們顯示,用戶明確地以及在其搜索行為中觀察到時都表達了對增強結果的偏愛。我們還展示了增強結果在幫助用戶評估搜索結果的相關性方面的有效性。最后,我們證明了我們可以有效地生成增強的結果,以覆蓋搜索結果頁面的很大一部分。
查看完整描述

3 回答

?
眼眸繁星

TA貢獻1873條經驗 獲得超9個贊

使用將對象轉換為單詞/索引對Object.entries()。使用迭代條目Array.reduce()。在reduce中,用迭代索引Array.forEach(),并將每個單詞分配給累加器(r)中的索引。用空格將單詞數組連接起來。


const userdata = {"\"Ten":[0],"blue":[1],"links\"":[2],"have":[3],"defined":[4],"web":[5,36,65],"search":[6,32,37,70,90,108,126],"results":[7,33,38,71,82,99,119],"for":[8,80],"the":[9,28,56,61,69,95,105],"last":[10],"fifteen":[11],"years":[12],"--":[13],"snippets":[14],"of":[15,30,63,97,107,125],"text":[16],"combined":[17],"with":[18,60],"document":[19],"titles":[20],"and":[21,46,52,85],"URLs.":[22],"In":[23],"this":[24],"paper,":[25],"we":[26,111,114],"establish":[27],"notion":[29],"enhanced":[31,81,98,118],"that":[34,54,75,113],"extend":[35],"to":[39,58,103,120],"include":[40],"multimedia":[41],"objects":[42],"such":[43],"as":[44],"images":[45],"video,":[47],"intent-specific":[48],"key":[49],"value":[50],"pairs,":[51],"elements":[53],"allow":[55],"user":[57],"interact":[59],"contents":[62],"a":[64,78,122],"page":[66],"directly":[67],"from":[68],"page.":[72],"We":[73,92],"show":[74,112],"users":[76,102],"express":[77],"preference":[79],"both":[83],"explicitly,":[84],"when":[86],"observed":[87],"in":[88,100],"their":[89],"behavior.":[91],"also":[93],"demonstrate":[94],"effectiveness":[96],"helping":[101],"assess":[104],"relevance":[106],"results.":[109],"Lastly,":[110],"can":[115],"efficiently":[116],"generate":[117],"cover":[121],"significant":[123],"fraction":[124],"result":[127],"pages.":[128]};


const result = Object.entries(userdata)

  .reduce((r, [word, indexes]) => {

    indexes.forEach(index => r[index] = word);

    

    return r;

  }, [])

  .join(' ');

  

console.log(result);


查看完整回答
反對 回復 2021-04-15
?
繁花不似錦

TA貢獻1851條經驗 獲得超4個贊

您可以遍歷該對象,然后

  • 取得金鑰名稱(word

  • 使用以下位置提供的位置(indexuserdata[word]

  • 在結果數組中定義要使用的索引和單詞,例如arrResult[index] = word

然后,使用' '定界符將該數組連接到字符串中

例如:

var userdata = {"\"Ten":[0],"blue":[1],"links\"":[2],"have":[3],"defined":[4],"web":[5,36,65],"search":[6,32,37,70,90,108,126],"results":[7,33,38,71,82,99,119],"for":[8,80],"the":[9,28,56,61,69,95,105],"last":[10],"fifteen":[11],"years":[12],"--":[13],"snippets":[14],"of":[15,30,63,97,107,125],"text":[16],"combined":[17],"with":[18,60],"document":[19],"titles":[20],"and":[21,46,52,85],"URLs.":[22],"In":[23],"this":[24],"paper,":[25],"we":[26,111,114],"establish":[27],"notion":[29],"enhanced":[31,81,98,118],"that":[34,54,75,113],"extend":[35],"to":[39,58,103,120],"include":[40],"multimedia":[41],"objects":[42],"such":[43],"as":[44],"images":[45],"video,":[47],"intent-specific":[48],"key":[49],"value":[50],"pairs,":[51],"elements":[53],"allow":[55],"user":[57],"interact":[59],"contents":[62],"a":[64,78,122],"page":[66],"directly":[67],"from":[68],"page.":[72],"We":[73,92],"show":[74,112],"users":[76,102],"express":[77],"preference":[79],"both":[83],"explicitly,":[84],"when":[86],"observed":[87],"in":[88,100],"their":[89],"behavior.":[91],"also":[93],"demonstrate":[94],"effectiveness":[96],"helping":[101],"assess":[104],"relevance":[106],"results.":[109],"Lastly,":[110],"can":[115],"efficiently":[116],"generate":[117],"cover":[121],"significant":[123],"fraction":[124],"result":[127],"pages.":[128]};


let arrResult = [];


for (let word in userdata)

{

  userdata[word].forEach((i) =>

  {

    arrResult[i] = word;

  });

}

let result = arrResult.join(' ');

console.log(result);


查看完整回答
反對 回復 2021-04-15
  • 3 回答
  • 0 關注
  • 223 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號