Before diving into the world of programming, it's crucial to grasp the distinction between an "array" and "JSON".
An array can be thought of as a collection of elements, such as [2015, 2016, 2017, 2018]
.
The construct you've assembled (
[0:"2015", 1:"2016", 2:"2017", 3:"2018"]
) deviates from the expected JavaScript syntax.
What you should be aiming for is a JSON object like
{0:"2015", 1:"2016", 2:"2017", 3:"2018"}
. Once you have that in place, you can utilize the
Object.values()
function.
const myObject = {
0: "2015",
1: "2016",
2: "2017",
3: "2018"
};
const val = Object.values(myObject);
console.log(val);