0

I am trying to display the count of datapasar object and the value at the second index of datapasar. I think javascript will display ' nama pasar: pasar losari jumlah data:5 '
but the browser not displaying anything.This is my script:

var datapasar = {
  "datapasar": [
    {
      "id": "1",
      "nama": "pasar bandung"
    },
    {
      "id": "2",
      "nama": "pasar losari"
    },
    {
      "id": "3",
      "nama": "pasar losari 2"
    }
  ]
};

alert('nama pasar:'+ datapasar[1]['nama'] + 'kota :' +'jumlah data'+ datapasar.length);

1 Answer 1

1

in that case it would look like this:

var datapasar = {
  "datapasar": [
    {
      "id": "1",
      "nama": "pasar bandung"
    },
    {
      "id": "2",
      "nama": "pasar losari"
    },
    {
      "id": "3",
      "nama": "pasar losari 2"
    }
  ]
};

alert('nama pasar:'+ datapasar.datapasar[1]['nama'] + 'kota :' +'jumlah data'+ datapasar.datapasar.length);

datapasar is the name of your variable and the first and only key of your object which contains an array.

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

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.