如何迭代特定列表的属性

发布于 2025-01-17 20:31:44 字数 828 浏览 3 评论 0原文

我是 JS 新手,我已经将 this 中的所有内容推送到我的 arraylist MyList 但我想将所有 title 属性推送到我的 titleList

在此处输入图像描述

我不知道是否需要使用增量获取所有标题,所以我发现了这个对我来说似乎合乎逻辑的例子:

...
const MyList = []
MyList.push(json_response)

const titleList = []

Object.keys(MyList).forEach(key => {
   console.log(key, obj[title]);
   titleList.push([title])
 });

我发现了这个:

 ReferenceError: Cannot access 'title' before initialization
    at /Users/mac/Desktop/My_test/index.js:55:28
    at Array.map (<anonymous>)
    at /Users/mac/Desktop/My_test/index.js:42:33

Im new on JS and i already push all content from this on my arraylist MyList but i wanted to get all title property to push on my titleList

enter image description here

I don't know if i need to use incrementation get all title, so i found this exemple which seems logical to me :

...
const MyList = []
MyList.push(json_response)

const titleList = []

Object.keys(MyList).forEach(key => {
   console.log(key, obj[title]);
   titleList.push([title])
 });

and i found this:

 ReferenceError: Cannot access 'title' before initialization
    at /Users/mac/Desktop/My_test/index.js:55:28
    at Array.map (<anonymous>)
    at /Users/mac/Desktop/My_test/index.js:42:33

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆梦 2025-01-24 20:31:44

如果 json_response 有数据,此时标题尚未定义,请尝试此...

const MyList    = []
const titleList = []

MyList.push(json_response)

MyList.forEach(item => {
  console.log(item);
  titleList.push(item.title)
});

title is not defined at this point provided json_response has data try this...

const MyList    = []
const titleList = []

MyList.push(json_response)

MyList.forEach(item => {
  console.log(item);
  titleList.push(item.title)
});

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文