0

I am new to coding.Please be kind to answer :)

I have an array of objects.

[ { UPDATED_BY: '2301132411' },
  { UPDATED_BY: '1432007924' },
  { UPDATED_BY: '973551993' },
  { UPDATED_BY: '1082191138' },
  { UPDATED_BY: '1079399273' } ]

I want the output in below format: ('2301132411','1432007924','973551993','1082191138','1079399273')

I was able to output one value by using below command.I want to use loop here to fetch all the values.Please help with the exact code.Thanks in advance.

var k={};
var arr = [ { UPDATED_BY: '2301132411' },
  { UPDATED_BY: '1432007924' },
  { UPDATED_BY: '973551993' },
  { UPDATED_BY: '1082191138' },
  { UPDATED_BY: '1079399273' } ];
  k=arr[0];
console.log(k);

output: 1432007924

3 Answers 3

1

var arr = [
  {UPDATED_BY: '2301132411'},
  {UPDATED_BY: '1432007924'},
  {UPDATED_BY: '973551993'},
  {UPDATED_BY: '1082191138'},
  {UPDATED_BY: '1079399273'
}]

arr = '(' + arr.map(function (item) {
  return item.UPDATED_BY
}) + ')';

console.log(arr);

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

Comments

1

If I have understood your question correctly, You can use Array#map function to achieve this as follows:

var arr = [
  { UPDATED_BY: '2301132411' },
  { UPDATED_BY: '1432007924' },
  { UPDATED_BY: '973551993' },
  { UPDATED_BY: '1082191138' },
  { UPDATED_BY: '1079399273' }
];
var k = arr.map(function(obj) {
  return obj['UPDATED_BY'];
});

console.log(k); // If you wants an array of all values
console.log('(' + k + ')'); // In case you wants one complete string

Comments

0

Try this:

var output = [];
for(var i = 0;i < arr.length; i++) {
    output.push(arr[i]['UPDATED_BY']);
}
console.log(output);

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.