0

I want to remove the first element from a JSON-array. The Json-array has this format:

[{"hyperperiod":1200},{"x":"Process0Application1Data1","y": 
["0.00","5.00"],"fillColor":"#008FFB"}, ...]

The Result should be:

[{"x":"Process0Application1Data1","y": 
["0.00","5.00"],"fillColor":"#008FFB"}, ...]

I tried using splice

console.log(response.data);
response.data.splice(0, 1);
console.log(response.data);
3
  • What have you tried so far? There are many approaches to removing the first element of an array Commented Oct 12, 2022 at 15:00
  • You're going to need to edit the question. Include a minimal reproducible example which shows an explanation of what you mean by "does not work". Commented Oct 12, 2022 at 15:04
  • 1
    I tried this: response.data.splice(0, 1); Commented Oct 12, 2022 at 15:38

1 Answer 1

1

If you just one to remove the first item from an array, regardless of what type of array it is you can use shift(). https://www.w3schools.com/jsref/jsref_shift.asp

In your code that would simply be:

response.data.shift();
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.