-1

This is the results I am getting using console.log(res)

{d: Array(4)}
d: Array(4)
0: {__type: "Claim_Inbox+SubClaims", Claim_detail: 12, Claim_id: 123, …}
1: {__type: "Claim_Inbox+SubClaims", Claim_detail: 12, Claim_id: 124, …}
2: {__type: "Claim_Inbox+SubClaims", Claim_detail: 12, Claim_id: 125, …}
3: {__type: "Claim_Inbox+SubClaims", Claim_detail: 12, Claim_id: 126,…}
length: 4
__proto__: Array(0)
__proto__: Object

Using the following code I am getting the list of keys:values

var counter = 0;
$.each(res.d[counter ], function (key, value) {
   console.log(key + ": " + value);
   counter++;
});

how can I read a specific value like Claim_id ? I can use Switch() but maybe there is another way

4

1 Answer 1

0

First of all, it is not an Object, it is an Array. Second, depending on what you want, you can use forEach to loop over the array and show or assign or do whatever you need with the id OR use map to construct a new array with the selected values.

const array = [
  { __type: "Claim_Inbox+SubClaims", Claim_detail: 12, Claim_id: 123 },
  { __type: "Claim_Inbox+SubClaims", Claim_detail: 12, Claim_id: 124 },
  { __type: "Claim_Inbox+SubClaims", Claim_detail: 12, Claim_id: 125 },
  { __type: "Claim_Inbox+SubClaims", Claim_detail: 12, Claim_id: 126 }
];

array.forEach(item => console.log(item['Claim_id']); );

console.log("--------------------");

// Generate a new array copy
const result = array.map(item => item['Claim_id']);

console.log(result)

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

3 Comments

Array is an Object in JS
@fard yes, they are, but also are functions.... not for that you can loop over a function.... the base of javascript are objects, but they are not the same type of object ;)
But you can't say that Arrat is not an object, like you do in your first sentence @PrinceHernandez

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.