Convert a json array of objects into a different format2019 Community Moderator ElectionJavascript efficiency: 'for' vs 'forEach'Detecting an undefined object propertyWhat is the most efficient way to deep clone an object in JavaScript?How do I check if an array includes an object in JavaScript?Can comments be used in JSON?What is the correct JSON content type?Checking if a key exists in a JavaScript object?Why does Google prepend while(1); to their JSON responses?How to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?
Counting all the hearts
Declaring and defining template, and specialising them
Does a warlock using the Darkness/Devil's Sight combo still have advantage on ranged attacks against a target outside the Darkness?
How is the wildcard * interpreted as a command?
weren't playing vs didn't play
Is "history" a male-biased word ("his+story")?
Is it possible to avoid unpacking when merging Association?
How many characters using PHB rules does it take to be able to have access to any PHB spell at the start of an adventuring day?
What are actual Tesla M60 models used by AWS?
Shifting between bemols (flats) and diesis (sharps)in the key signature
Accountant/ lawyer will not return my call
Should I tell my boss the work he did was worthless
When traveling to Europe from North America, do I need to purchase a different power strip?
Are all players supposed to be able to see each others' character sheets?
How to secure an aircraft at a transient parking space?
If I receive an SOS signal, what is the proper response?
Why would one plane in this picture not have gear down yet?
Definition of Statistic
How can I ensure my trip to the UK will not have to be cancelled because of Brexit?
Vocabulary for giving just numbers, not a full answer
Find longest word in a string: are any of these algorithms good?
What was the Kree's motivation in Captain Marvel?
Intuition behind counterexample of Euler's sum of powers conjecture
Are there historical instances of the capital of a colonising country being temporarily or permanently shifted to one of its colonies?
Convert a json array of objects into a different format
2019 Community Moderator ElectionJavascript efficiency: 'for' vs 'forEach'Detecting an undefined object propertyWhat is the most efficient way to deep clone an object in JavaScript?How do I check if an array includes an object in JavaScript?Can comments be used in JSON?What is the correct JSON content type?Checking if a key exists in a JavaScript object?Why does Google prepend while(1); to their JSON responses?How to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?
How do I convert the following sample response data to the desired JSON format listed below? Thank you.
My logic
arr = arr.map((e) => e.title = JSON.parse(e.title.replace(/'/g, '"')).title; return e; )
My current response data
arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]
Desired JSON format
arr = [
id: 0,
title: "'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'YAHSHUA', 'instruction': '?', 'created_at': '2019-03-06'",
,
id: 1,
title: "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Exam2', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
]
javascript arrays json object
add a comment |
How do I convert the following sample response data to the desired JSON format listed below? Thank you.
My logic
arr = arr.map((e) => e.title = JSON.parse(e.title.replace(/'/g, '"')).title; return e; )
My current response data
arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]
Desired JSON format
arr = [
id: 0,
title: "'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'YAHSHUA', 'instruction': '?', 'created_at': '2019-03-06'",
,
id: 1,
title: "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Exam2', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
]
javascript arrays json object
add a comment |
How do I convert the following sample response data to the desired JSON format listed below? Thank you.
My logic
arr = arr.map((e) => e.title = JSON.parse(e.title.replace(/'/g, '"')).title; return e; )
My current response data
arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]
Desired JSON format
arr = [
id: 0,
title: "'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'YAHSHUA', 'instruction': '?', 'created_at': '2019-03-06'",
,
id: 1,
title: "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Exam2', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
]
javascript arrays json object
How do I convert the following sample response data to the desired JSON format listed below? Thank you.
My logic
arr = arr.map((e) => e.title = JSON.parse(e.title.replace(/'/g, '"')).title; return e; )
My current response data
arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]
Desired JSON format
arr = [
id: 0,
title: "'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'YAHSHUA', 'instruction': '?', 'created_at': '2019-03-06'",
,
id: 1,
title: "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Exam2', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
]
javascript arrays json object
javascript arrays json object
edited 2 days ago
georgeawg
33.9k105270
33.9k105270
asked Mar 7 at 6:39
Jhon CaylogJhon Caylog
8410
8410
add a comment |
add a comment |
10 Answers
10
active
oldest
votes
Try below code,
Because if you are using forEach or something it will affect your code performance.
I will recommend this way if you want to handle large data's. If you have less data then use other answers above to achieve your output with less code.
For your reference Javascript efficiency: 'for' vs 'forEach'.
var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
];
var result = [];
for(let i=0;i<arr.length;i++)
result.push(id: i, title:arr[i]);
console.log(result);
For loop analysis report : https://github.com/dg92/Performance-Analysis-JS
add a comment |
Um, just
arr.map((title, id) => ( title, id ))
add a comment |
You can use map()
to return the desired output:
const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
const result = arr.map((item, index) => (
id: index,
title: item
));
console.log(result);
In this way, you return an array of objects that have a title
property of type string
. If you want to output the title
value as an object, you can parse the value with JSON.parse()
:
const result = arr.map((item, index) => (
id: index,
title: JSON.parse(item)
));
add a comment |
It's not difficult, you have to map the array as you were doing, and return the new object:
arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]
mapped = arr.map((elem, index) =>
return (
id: index,
title: elem
);
);
console.log(mapped);
add a comment |
use currElement, index as the parameter of map then return the new object of "id":index,"title":currElement
let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
let newArr =arr.map((currElement, index) =>
return "id":index,"title":currElement;
);
console.log(newArr);
add a comment |
Using forEach loop create an object with required properties and replace the original object in the array
var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
]
arr.forEach((e, i) =>
arr[i] = id:i,title:e;
)
console.log(arr)
add a comment |
try this
let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
let newArr =arr.map((element, index) =>
return "id":index,"title":element;
);
console.log(newArr);
New contributor
add a comment |
arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]
for (var k = 0; k < arr.length; k++)
arr[k] = 'id':k, 'title': arr[k] ;
console.log(arr);
add a comment |
You can use .map
where the index is the id
:
const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'", "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"],
res = arr.map((title, id) => (id, title));
console.log(res);
add a comment |
var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
var new_arr = [];
for(var i=0; i< arr.length; i++)
new_arr[i] = 'id':i, 'title':arr[i]
console.log(JSON.stringify(new_arr));
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55037535%2fconvert-a-json-array-of-objects-into-a-different-format%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
10 Answers
10
active
oldest
votes
10 Answers
10
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try below code,
Because if you are using forEach or something it will affect your code performance.
I will recommend this way if you want to handle large data's. If you have less data then use other answers above to achieve your output with less code.
For your reference Javascript efficiency: 'for' vs 'forEach'.
var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
];
var result = [];
for(let i=0;i<arr.length;i++)
result.push(id: i, title:arr[i]);
console.log(result);
For loop analysis report : https://github.com/dg92/Performance-Analysis-JS
add a comment |
Try below code,
Because if you are using forEach or something it will affect your code performance.
I will recommend this way if you want to handle large data's. If you have less data then use other answers above to achieve your output with less code.
For your reference Javascript efficiency: 'for' vs 'forEach'.
var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
];
var result = [];
for(let i=0;i<arr.length;i++)
result.push(id: i, title:arr[i]);
console.log(result);
For loop analysis report : https://github.com/dg92/Performance-Analysis-JS
add a comment |
Try below code,
Because if you are using forEach or something it will affect your code performance.
I will recommend this way if you want to handle large data's. If you have less data then use other answers above to achieve your output with less code.
For your reference Javascript efficiency: 'for' vs 'forEach'.
var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
];
var result = [];
for(let i=0;i<arr.length;i++)
result.push(id: i, title:arr[i]);
console.log(result);
For loop analysis report : https://github.com/dg92/Performance-Analysis-JS
Try below code,
Because if you are using forEach or something it will affect your code performance.
I will recommend this way if you want to handle large data's. If you have less data then use other answers above to achieve your output with less code.
For your reference Javascript efficiency: 'for' vs 'forEach'.
var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
];
var result = [];
for(let i=0;i<arr.length;i++)
result.push(id: i, title:arr[i]);
console.log(result);
For loop analysis report : https://github.com/dg92/Performance-Analysis-JS
edited Mar 7 at 7:11
answered Mar 7 at 6:53
DineshDinesh
4,89093675
4,89093675
add a comment |
add a comment |
Um, just
arr.map((title, id) => ( title, id ))
add a comment |
Um, just
arr.map((title, id) => ( title, id ))
add a comment |
Um, just
arr.map((title, id) => ( title, id ))
Um, just
arr.map((title, id) => ( title, id ))
answered Mar 7 at 6:44
Jonas WilmsJonas Wilms
61.1k53255
61.1k53255
add a comment |
add a comment |
You can use map()
to return the desired output:
const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
const result = arr.map((item, index) => (
id: index,
title: item
));
console.log(result);
In this way, you return an array of objects that have a title
property of type string
. If you want to output the title
value as an object, you can parse the value with JSON.parse()
:
const result = arr.map((item, index) => (
id: index,
title: JSON.parse(item)
));
add a comment |
You can use map()
to return the desired output:
const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
const result = arr.map((item, index) => (
id: index,
title: item
));
console.log(result);
In this way, you return an array of objects that have a title
property of type string
. If you want to output the title
value as an object, you can parse the value with JSON.parse()
:
const result = arr.map((item, index) => (
id: index,
title: JSON.parse(item)
));
add a comment |
You can use map()
to return the desired output:
const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
const result = arr.map((item, index) => (
id: index,
title: item
));
console.log(result);
In this way, you return an array of objects that have a title
property of type string
. If you want to output the title
value as an object, you can parse the value with JSON.parse()
:
const result = arr.map((item, index) => (
id: index,
title: JSON.parse(item)
));
You can use map()
to return the desired output:
const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
const result = arr.map((item, index) => (
id: index,
title: item
));
console.log(result);
In this way, you return an array of objects that have a title
property of type string
. If you want to output the title
value as an object, you can parse the value with JSON.parse()
:
const result = arr.map((item, index) => (
id: index,
title: JSON.parse(item)
));
const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
const result = arr.map((item, index) => (
id: index,
title: item
));
console.log(result);
const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
const result = arr.map((item, index) => (
id: index,
title: item
));
console.log(result);
answered Mar 7 at 6:44
kapantzakkapantzak
9,63442750
9,63442750
add a comment |
add a comment |
It's not difficult, you have to map the array as you were doing, and return the new object:
arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]
mapped = arr.map((elem, index) =>
return (
id: index,
title: elem
);
);
console.log(mapped);
add a comment |
It's not difficult, you have to map the array as you were doing, and return the new object:
arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]
mapped = arr.map((elem, index) =>
return (
id: index,
title: elem
);
);
console.log(mapped);
add a comment |
It's not difficult, you have to map the array as you were doing, and return the new object:
arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]
mapped = arr.map((elem, index) =>
return (
id: index,
title: elem
);
);
console.log(mapped);
It's not difficult, you have to map the array as you were doing, and return the new object:
arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]
mapped = arr.map((elem, index) =>
return (
id: index,
title: elem
);
);
console.log(mapped);
arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]
mapped = arr.map((elem, index) =>
return (
id: index,
title: elem
);
);
console.log(mapped);
arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]
mapped = arr.map((elem, index) =>
return (
id: index,
title: elem
);
);
console.log(mapped);
answered Mar 7 at 6:44
JV LoboJV Lobo
2,97762140
2,97762140
add a comment |
add a comment |
use currElement, index as the parameter of map then return the new object of "id":index,"title":currElement
let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
let newArr =arr.map((currElement, index) =>
return "id":index,"title":currElement;
);
console.log(newArr);
add a comment |
use currElement, index as the parameter of map then return the new object of "id":index,"title":currElement
let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
let newArr =arr.map((currElement, index) =>
return "id":index,"title":currElement;
);
console.log(newArr);
add a comment |
use currElement, index as the parameter of map then return the new object of "id":index,"title":currElement
let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
let newArr =arr.map((currElement, index) =>
return "id":index,"title":currElement;
);
console.log(newArr);
use currElement, index as the parameter of map then return the new object of "id":index,"title":currElement
let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
let newArr =arr.map((currElement, index) =>
return "id":index,"title":currElement;
);
console.log(newArr);
let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
let newArr =arr.map((currElement, index) =>
return "id":index,"title":currElement;
);
console.log(newArr);
let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
let newArr =arr.map((currElement, index) =>
return "id":index,"title":currElement;
);
console.log(newArr);
answered Mar 7 at 6:45
Mohammad Ali RonyMohammad Ali Rony
2,5341818
2,5341818
add a comment |
add a comment |
Using forEach loop create an object with required properties and replace the original object in the array
var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
]
arr.forEach((e, i) =>
arr[i] = id:i,title:e;
)
console.log(arr)
add a comment |
Using forEach loop create an object with required properties and replace the original object in the array
var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
]
arr.forEach((e, i) =>
arr[i] = id:i,title:e;
)
console.log(arr)
add a comment |
Using forEach loop create an object with required properties and replace the original object in the array
var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
]
arr.forEach((e, i) =>
arr[i] = id:i,title:e;
)
console.log(arr)
Using forEach loop create an object with required properties and replace the original object in the array
var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
]
arr.forEach((e, i) =>
arr[i] = id:i,title:e;
)
console.log(arr)
var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
]
arr.forEach((e, i) =>
arr[i] = id:i,title:e;
)
console.log(arr)
var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
]
arr.forEach((e, i) =>
arr[i] = id:i,title:e;
)
console.log(arr)
answered Mar 7 at 6:46
ellipsisellipsis
7,8112929
7,8112929
add a comment |
add a comment |
try this
let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
let newArr =arr.map((element, index) =>
return "id":index,"title":element;
);
console.log(newArr);
New contributor
add a comment |
try this
let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
let newArr =arr.map((element, index) =>
return "id":index,"title":element;
);
console.log(newArr);
New contributor
add a comment |
try this
let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
let newArr =arr.map((element, index) =>
return "id":index,"title":element;
);
console.log(newArr);
New contributor
try this
let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
let newArr =arr.map((element, index) =>
return "id":index,"title":element;
);
console.log(newArr);
let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
let newArr =arr.map((element, index) =>
return "id":index,"title":element;
);
console.log(newArr);
let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
let newArr =arr.map((element, index) =>
return "id":index,"title":element;
);
console.log(newArr);
New contributor
New contributor
answered Mar 7 at 15:12
Shahriar MahirShahriar Mahir
292
292
New contributor
New contributor
add a comment |
add a comment |
arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]
for (var k = 0; k < arr.length; k++)
arr[k] = 'id':k, 'title': arr[k] ;
console.log(arr);
add a comment |
arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]
for (var k = 0; k < arr.length; k++)
arr[k] = 'id':k, 'title': arr[k] ;
console.log(arr);
add a comment |
arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]
for (var k = 0; k < arr.length; k++)
arr[k] = 'id':k, 'title': arr[k] ;
console.log(arr);
arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]
for (var k = 0; k < arr.length; k++)
arr[k] = 'id':k, 'title': arr[k] ;
console.log(arr);
answered Mar 7 at 6:51
Murali NepalliMurali Nepalli
1635
1635
add a comment |
add a comment |
You can use .map
where the index is the id
:
const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'", "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"],
res = arr.map((title, id) => (id, title));
console.log(res);
add a comment |
You can use .map
where the index is the id
:
const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'", "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"],
res = arr.map((title, id) => (id, title));
console.log(res);
add a comment |
You can use .map
where the index is the id
:
const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'", "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"],
res = arr.map((title, id) => (id, title));
console.log(res);
You can use .map
where the index is the id
:
const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'", "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"],
res = arr.map((title, id) => (id, title));
console.log(res);
const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'", "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"],
res = arr.map((title, id) => (id, title));
console.log(res);
const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'", "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"],
res = arr.map((title, id) => (id, title));
console.log(res);
edited Mar 7 at 6:51
answered Mar 7 at 6:44
Nick ParsonsNick Parsons
9,4682826
9,4682826
add a comment |
add a comment |
var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
var new_arr = [];
for(var i=0; i< arr.length; i++)
new_arr[i] = 'id':i, 'title':arr[i]
console.log(JSON.stringify(new_arr));
add a comment |
var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
var new_arr = [];
for(var i=0; i< arr.length; i++)
new_arr[i] = 'id':i, 'title':arr[i]
console.log(JSON.stringify(new_arr));
add a comment |
var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
var new_arr = [];
for(var i=0; i< arr.length; i++)
new_arr[i] = 'id':i, 'title':arr[i]
console.log(JSON.stringify(new_arr));
var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];
var new_arr = [];
for(var i=0; i< arr.length; i++)
new_arr[i] = 'id':i, 'title':arr[i]
console.log(JSON.stringify(new_arr));
answered Mar 7 at 6:53
Kausha ShahKausha Shah
635
635
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55037535%2fconvert-a-json-array-of-objects-into-a-different-format%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown