-1

I have array of object like this :

enter image description here

I need to select only the array which has coreSystemID = 'T24' so I tried credsArr.find() it shows my .find is not a function.

below is my code:

var creds = credsArr.find(x => x.coreSystemID === 'T24')

And I should use the index value like this - credsArr[3053], because the index may vary so I need to select the array which has coreSystemID = 'T24'

2
  • 6
    credsArr is an object, not an array, the same for its values, 3052 and 3053... Commented Dec 2, 2019 at 11:37
  • 1
    If you don't need the key (3053): Object.values(credsArr).find(cred => cred.coreSystemID === "T24") Commented Dec 2, 2019 at 11:41

2 Answers 2

2
let keys = Oject.keys(credsArr).filter(key => credsArr[key].coreSystemID==='T24')

keys will have all the keys of credsArr having credsArr[key].coreSystemID as 'T24'

let systemT24 = credsArr[keys[0]] will give you the object you are looking for given that there is only one object with coreSystemID as 'T24'.

If you have multiple objects that might have coreSystemID as 'T24' you can map it to a new array like this:

let systemT24 = keys.map(key => credsArr[key])
Sign up to request clarification or add additional context in comments.

2 Comments

i'm gettign output as like this - 0: "3053"... Can you assist by selecting the all element in this array "3053"?
@Mar1009 Check out the modified answer.
1

You can use Object.values(credsArr):

 var creds = Object.values(credsArr).find(x => x.coreSystemID === 'T24');

or if you need key of the object:

var creds = Object.entries(credsArr).find(x => x[1].coreSystemID === 'T24');
let key = creds[0];
let value = creds[1];

1 Comment

it says Object.values is not a function is not a function

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.