- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2017 01:16 AM
What should be the ideal solution for this
Input: var inc2 = {
num: 'INC111',
sd: 'email'
};
var inc2 = {
num: 'INC222',
foo: 'internet'
}
var arr = [];
arr.push(inc2,inc1);
Index of the inc1 object to be 1.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2017 06:54 PM
From the title, i see you are looking for getting the index of an array in Javascript object( based on a value)? Please correct me if I am wrong.
If thats the case, you can use 'map' function. Also, I think the inc2 one line # 1 is typo, I corrected it.
var inc1 = {
num: 'INC111',
sd: 'email'
};
var inc2 = {
num: 'INC222',
foo: 'internet'
}
var arr = [];
arr.push(inc2,inc1);
pos = arr.map(function(input) { return input.num; }).indexOf('INC111');
gs.log(pos);
Hope this helps. Mark the answer as correct/helpful based on impact.
Thanks
Antin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2017 08:09 PM
Sure!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2017 09:06 AM
Thanks. This should do though I wanted it little differently.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2017 09:45 AM
Glad it helped. But can you explain what you wanted differently?
Thanks
Antin