0

I have these below JSON data:

{
"0": {
    "jQuery331045811028719032642": {
        "stepCount": 1,
        "captionSize": 0,
        "countdown": true,
        "countdownAlertLimit": 10,
        "displayCaptions": false,
        "displayDays": 0,
        "displayHours": true,
        "fontFamily": "Verdana, sans-serif",
        "fontSize": 0,
        "lang": "en",
        "languages": {},
        "seconds": 2609,
        "start": true,
        "theme": "white",
        "width": 4,
        "height": 30,
        "gap": 11,
        "vals": [0, 0, 4, 3, 2, 9],
        "limits": [2, 9, 5, 9, 5, 9],
        "iSec": 5,
        "iHour": 1,
        "tickTimeout": 1000,
        "intervalId": 1,
        "tickCount": 0,
        "timeTo": "2021-06-12T15:14:00.000Z",
        "options": {
            "timeTo": "2021-06-12T15:14:00.000Z",
            "start": true,
            "theme": "white",
            "seconds": 2609
        },
        "sec": 2609,
        "ttStartTime": 1623508230144
    },
    "jQuery331045811028719032641": {
        "hasDataAttrs": true
    }
},
"length": 1
}

Assume above array variable is var data;

For this subarray jQuery331045811028719032642 is auto generate.

My question, how to get seconds array value using jQuery?

I tried this:

alert(data[0].seconds);

but it returns undefined.

1
  • There is no seconds array in the complete object. Commented Jun 13, 2021 at 12:28

3 Answers 3

1

You can get the seconds using Object.values

const data = {
  "0": {
    jQuery331045811028719032642: {
      stepCount: 1,
      captionSize: 0,
      countdown: true,
      countdownAlertLimit: 10,
      displayCaptions: false,
      displayDays: 0,
      displayHours: true,
      fontFamily: "Verdana, sans-serif",
      fontSize: 0,
      lang: "en",
      languages: {},
      seconds: 2609,
      start: true,
      theme: "white",
      width: 4,
      height: 30,
      gap: 11,
      vals: [0, 0, 4, 3, 2, 9],
      limits: [2, 9, 5, 9, 5, 9],
      iSec: 5,
      iHour: 1,
      tickTimeout: 1000,
      intervalId: 1,
      tickCount: 0,
      timeTo: "2021-06-12T15:14:00.000Z",
      options: {
        timeTo: "2021-06-12T15:14:00.000Z",
        start: true,
        theme: "white",
        seconds: 2609,
      },
      sec: 2609,
      ttStartTime: 1623508230144,
    },
    jQuery331045811028719032641: {
      hasDataAttrs: true,
    },
  },
  length: 1,
};
const zeroObj = data["0"];
const result = Object.values(zeroObj)[0].seconds;
console.log(result);

Sign up to request clarification or add additional context in comments.

Comments

1

You can try to use this code

const arrayData = Object.values(data["0"]);
console.log(arrayData[0].seconds);

Comments

0

You can try any of them to get the seconds value.

1- Use Object.values to get the values inside the Object like below

let res = Object.values(data["0"]);
let seconds = res.seconds; // This will give you value of seconds.

2- Use Object.keys to get the keys of object and get the data using that key.

let keys = Object.keys(data[0]);
let seconds = data[0][keys[0]].seconds; 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.