api返回一个带有编号和命名键的数组

问题描述 投票:2回答:1

所以我正在组建一个NextJS + Ghost CMS解耦博客,并正在使用Ghost JS API(特别是Content API Client Library)。

当我使用以下运行我的查询时...

api.posts
    .browse({ 
      limit: 5,
      page: 1,
      include: 'authors',
      fields: 'excerpt,custom_excerpt,title,id,slug,'
    })  
    .then((posts) => {
      console.log(posts);
        return posts;
      })
    .catch((err) => {
        console.error(err);
    });

...我发现它返回一个数组。该阵列具有典型的qazxsw poi qazxsw poi qazxsw poi ...键。我惊讶地发现它还有一个命名的最后一项:0

从chrome JS控制台查看图像。

1

这里发生了什么。我是否错过了JS101关于数组中字符串命名键的课程?

javascript ghost-blog
1个回答
1
投票

来自2

数组是类似列表的对象,其原型具有执行遍历和变异操作的方法。

换句话说,它们是一种特殊类型的对象。所以,和其他meta一样,你可以添加is this even possible。然而,他的MDN上的objects只能穿越named properties。检查下一个示例:

methods
prototype

现在,我相信chrome JS控制台的实现基于numeric-properties原型方法,可能是let arr = [1,2,3,4]; arr.meta = {foo: "bar"}; console.log("standard arr display: ", arr); console.log("arr.meta: ", arr.meta); console.log("Own Property Names: ", Object.getOwnPropertyNames(arr));,以显示他的所有属性(包括.as-console {background-color:black !important; color:lime;} .as-console-wrapper {max-height:100% !important; top:0;}长度)和值。您可以读取object以了解如何使用Object.getOwnPropertNames()参数定义non-enumerable属性。

© www.soinside.com 2019 - 2024. All rights reserved.