const originalData = [
{"first":"Gretchen","last":"Kuphal","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4f283d2a2a21382023297a7b0f28222e2623612c2022">[email protected]</a>","address":"416
Lesch Road","created":"March 1, 2012","balance":"$9,782.26"}];
1. Simply copying the array:
const duplicateData = [...originalData];
- If you want all values, loop through them
- To access a single value, you can do this:
alert(duplicateData[0].first);
console.log(duplicateData[0].first);
You can also perform edits like below
const originalData = [
{"first":"Gretchen","last":"Kuphal","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bcdbced9d9d2cbd3d0da8988fcdbd1ddd5d092dfd3d1">[email protected]</a>","address":"416 Lesch Road","created":"March 1, 2012","balance":"$9,782.26"},
{"first":"Morton","last":"Mayer","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cdbeaca1a0a2a3bebcb8a4bfbfa8a1fff88daaa0aca4a1e3aea2a0">[email protected]</a>","address":"1602 Bernhard Parkway","created":"April 29, 2017","balance":"$6,596.11"},
{"first":"Catalina","last":"Daugherty","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2467455045484d4a450a604551434c4156505d64424d484b49414a450a4a454941">[email protected]</a>","address":"11893 Kali Vista","created":"October 16, 2008","balance":"$6,372.86"},
{"first":"Orpha","last":"Heaney","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1d69686f6c6872746e786a72717b2f2f5d7a707c7471337e7270">[email protected]</a>","address":"8090 Chris Stream","created":"November 21, 2015","balance":"$9,596.26"},
{"first":"Reva","last":"Mohr","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1a487f6c7b34577572685a757e7b34747f6e">[email protected]</a>","address":"0291 Kailyn Stravenue","created":"November 6, 2014","balance":"$4,768.37"},
{"first":"Loma","last":"Keeling","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2551505754504a4c5640424c5744434340151c654248444c490b464a48">[email protected]</a>","address":"84460 Samson Knoll","created":"June 13, 2017","balance":"$9,361.16"}
];
const duplicateData = [];
for (let obj of originalData) {
duplicateData.push(obj.first);
}
// print
for (let name of duplicateData) {
console.log(name);
}