小编JC *_*cia的帖子

如何在Javascript中切片对象?

我试图使用Array.prototype切片对象,但是它返回一个空数组,除了传递参数之外是否有任何方法来切片对象,或者只是我的代码有错误?谢谢!!

var my_object = {
 0: 'zero',
 1: 'one',
 2: 'two',
 3: 'three',
 4: 'four'
};

var sliced = Array.prototype.slice.call(my_object, 4);
console.log(sliced);
Run Code Online (Sandbox Code Playgroud)

javascript arrays arguments object slice

17
推荐指数
5
解决办法
4万
查看次数

嵌套一些具有特定名称的键的对象组数组

我有这个对象数组,我需要修改它以使渲染更容易。

const items = [
  {
    tab: 'Results',
    section: '2017',
    title: 'Full year Results',
    description: 'Something here',
  },
    {
    tab: 'Results',
    section: '2017',
    title: 'Half year Results',
    description: 'Something here',
  },
    {
    tab: 'Reports',
    section: 'Marketing',
    title: 'First Report',
    description: 'Something here',
  },
  ...
];
Run Code Online (Sandbox Code Playgroud)

我正在尝试修改它,按特定键对它们进行分组。这个想法是有这个输出。如您所见,键的名称可能与项目中的实际名称不同。我认为这与以前的帖子有点不同。

const output = [
  {
    tab: 'Results',
    sections: [
      {
         section: '2017',
         items: [ { 'item that belongs here' }, { ... } ],
      },
  },
  {
    tab: 'Reports',
    sections: [
      {
         section: 'Marketing', …
Run Code Online (Sandbox Code Playgroud)

javascript arrays grouping nested object

4
推荐指数
1
解决办法
2651
查看次数

使用Postman的Basic Auth GET请求,但不是浏览器

我正在使用odata api,当我使用邮递员做GET请求时,工作完美,我得到的回应正如我所期待的那样. 邮差要求

但是当我使用来自我的React应用程序的获取请求时,请求会抛出401,使用与之前在Postman中使用的相同的标头.它说的Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 401.

有关如何解决此请求的任何想法?谢谢!

fetch('https://api4.successfactors.com/odata/v2/', {
  method: 'GET',
  headers: {
    authorization: `Basic ${auth}`, //auth is the encoded base64 username:password
  },
})
  .then(response => response.json())
  .then((response) => {
    console.log('in response: ', response);
  })
  .catch((error) => {
    console.log('in fetchJobs error: ', error);
  });
Run Code Online (Sandbox Code Playgroud)

这是我得到的401 ...... 在此输入图像描述

javascript get request fetch odata

3
推荐指数
2
解决办法
9053
查看次数

标签 统计

javascript ×3

arrays ×2

object ×2

arguments ×1

fetch ×1

get ×1

grouping ×1

nested ×1

odata ×1

request ×1

slice ×1