How to merge and return new array from object in es6 The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceHow can I merge properties of two JavaScript objects dynamically?How do I remove a property from a JavaScript object?How do I check if an array includes an object in JavaScript?How to append something to an array?How to insert an item into an array at a specific index (JavaScript)?How do I correctly clone a JavaScript object?Sort array of objects by string property valueHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?How do I return the response from an asynchronous call?

The following signatures were invalid: EXPKEYSIG 1397BC53640DB551

Didn't get enough time to take a Coding Test - what to do now?

Scientific Reports - Significant Figures

What can I do if neighbor is blocking my solar panels intentionally?

Finding the path in a graph from A to B then back to A with a minimum of shared edges

Is there a writing software that you can sort scenes like slides in PowerPoint?

Match Roman Numerals

Take groceries in checked luggage

Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?

How did passengers keep warm on sail ships?

How to copy the contents of all files with a certain name into a new file?

Is it ok to offer lower paid work as a trial period before negotiating for a full-time job?

Can a 1st-level character have an ability score above 18?

Mortgage adviser recommends a longer term than necessary combined with overpayments

Can the prologue be the backstory of your main character?

The variadic template constructor of my class cannot modify my class members, why is that so?

Typeface like Times New Roman but with "tied" percent sign

How can I protect witches in combat who wear limited clothing?

Arduino Pro Micro - switch off LEDs

How should I replace vector<uint8_t>::const_iterator in an API?

Change bounding box of math glyphs in LuaTeX

how can a perfect fourth interval be considered either consonant or dissonant?

Derivation tree not rendering

What is this lever in Argentinian toilets?



How to merge and return new array from object in es6



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceHow can I merge properties of two JavaScript objects dynamically?How do I remove a property from a JavaScript object?How do I check if an array includes an object in JavaScript?How to append something to an array?How to insert an item into an array at a specific index (JavaScript)?How do I correctly clone a JavaScript object?Sort array of objects by string property valueHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?How do I return the response from an asynchronous call?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








10















Suppose there are two objects.



const a = [
id: '1-1-1', name: 'a111' ,
id: '1-1-2', name: 'a112' ,
id: '1-2-1', name: 'a121' ,
id: '1-2-2', name: 'a122' ,
id: '2-1-1', name: 'a211' ,
id: '2-1-2', name: 'a212'
]
const b = ['1-1', '1-2', '2-1']


and the result



 

'1-1':[
id: '1-1-1', name: 'a111' ,
id: '1-1-2', name: 'a112' ,
],
'1-2':[
id: '1-2-1', name: 'a121' ,
id: '1-2-2', name: 'a122' ,
],
'2-1':[
id: '2-1-1', name: 'a211' ,
id: '2-1-2', name: 'a212' ,
]



Basically, I want to group the data.



I use includes to check if the item from b to match the id from a. Then construct the new array.



This is my attempt(fiddle):



return b.map(item => a.map(jtem => 
if(jtem.id.includes(item))
return
[item]: jtem


))


For somehow, it doesn't work.



and, is there a clever way to avoid the nested for loop or map function?










share|improve this question
























  • Shouldn't the result be an object?

    – Jack Bashford
    Mar 25 at 7:02











  • @JackBashford Hey man, sry, u r right, I just updated it.

    – SPG
    Mar 25 at 7:08











  • Do you really want includes? I'd recommend startsWith

    – Bergi
    Mar 25 at 8:26











  • @Bergi thx, I think startWith is better

    – SPG
    Mar 26 at 0:30

















10















Suppose there are two objects.



const a = [
id: '1-1-1', name: 'a111' ,
id: '1-1-2', name: 'a112' ,
id: '1-2-1', name: 'a121' ,
id: '1-2-2', name: 'a122' ,
id: '2-1-1', name: 'a211' ,
id: '2-1-2', name: 'a212'
]
const b = ['1-1', '1-2', '2-1']


and the result



 

'1-1':[
id: '1-1-1', name: 'a111' ,
id: '1-1-2', name: 'a112' ,
],
'1-2':[
id: '1-2-1', name: 'a121' ,
id: '1-2-2', name: 'a122' ,
],
'2-1':[
id: '2-1-1', name: 'a211' ,
id: '2-1-2', name: 'a212' ,
]



Basically, I want to group the data.



I use includes to check if the item from b to match the id from a. Then construct the new array.



This is my attempt(fiddle):



return b.map(item => a.map(jtem => 
if(jtem.id.includes(item))
return
[item]: jtem


))


For somehow, it doesn't work.



and, is there a clever way to avoid the nested for loop or map function?










share|improve this question
























  • Shouldn't the result be an object?

    – Jack Bashford
    Mar 25 at 7:02











  • @JackBashford Hey man, sry, u r right, I just updated it.

    – SPG
    Mar 25 at 7:08











  • Do you really want includes? I'd recommend startsWith

    – Bergi
    Mar 25 at 8:26











  • @Bergi thx, I think startWith is better

    – SPG
    Mar 26 at 0:30













10












10








10


2






Suppose there are two objects.



const a = [
id: '1-1-1', name: 'a111' ,
id: '1-1-2', name: 'a112' ,
id: '1-2-1', name: 'a121' ,
id: '1-2-2', name: 'a122' ,
id: '2-1-1', name: 'a211' ,
id: '2-1-2', name: 'a212'
]
const b = ['1-1', '1-2', '2-1']


and the result



 

'1-1':[
id: '1-1-1', name: 'a111' ,
id: '1-1-2', name: 'a112' ,
],
'1-2':[
id: '1-2-1', name: 'a121' ,
id: '1-2-2', name: 'a122' ,
],
'2-1':[
id: '2-1-1', name: 'a211' ,
id: '2-1-2', name: 'a212' ,
]



Basically, I want to group the data.



I use includes to check if the item from b to match the id from a. Then construct the new array.



This is my attempt(fiddle):



return b.map(item => a.map(jtem => 
if(jtem.id.includes(item))
return
[item]: jtem


))


For somehow, it doesn't work.



and, is there a clever way to avoid the nested for loop or map function?










share|improve this question
















Suppose there are two objects.



const a = [
id: '1-1-1', name: 'a111' ,
id: '1-1-2', name: 'a112' ,
id: '1-2-1', name: 'a121' ,
id: '1-2-2', name: 'a122' ,
id: '2-1-1', name: 'a211' ,
id: '2-1-2', name: 'a212'
]
const b = ['1-1', '1-2', '2-1']


and the result



 

'1-1':[
id: '1-1-1', name: 'a111' ,
id: '1-1-2', name: 'a112' ,
],
'1-2':[
id: '1-2-1', name: 'a121' ,
id: '1-2-2', name: 'a122' ,
],
'2-1':[
id: '2-1-1', name: 'a211' ,
id: '2-1-2', name: 'a212' ,
]



Basically, I want to group the data.



I use includes to check if the item from b to match the id from a. Then construct the new array.



This is my attempt(fiddle):



return b.map(item => a.map(jtem => 
if(jtem.id.includes(item))
return
[item]: jtem


))


For somehow, it doesn't work.



and, is there a clever way to avoid the nested for loop or map function?







javascript ecmascript-6 ecmascript-7






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 7:04







SPG

















asked Mar 25 at 7:01









SPGSPG

2,452103359




2,452103359












  • Shouldn't the result be an object?

    – Jack Bashford
    Mar 25 at 7:02











  • @JackBashford Hey man, sry, u r right, I just updated it.

    – SPG
    Mar 25 at 7:08











  • Do you really want includes? I'd recommend startsWith

    – Bergi
    Mar 25 at 8:26











  • @Bergi thx, I think startWith is better

    – SPG
    Mar 26 at 0:30

















  • Shouldn't the result be an object?

    – Jack Bashford
    Mar 25 at 7:02











  • @JackBashford Hey man, sry, u r right, I just updated it.

    – SPG
    Mar 25 at 7:08











  • Do you really want includes? I'd recommend startsWith

    – Bergi
    Mar 25 at 8:26











  • @Bergi thx, I think startWith is better

    – SPG
    Mar 26 at 0:30
















Shouldn't the result be an object?

– Jack Bashford
Mar 25 at 7:02





Shouldn't the result be an object?

– Jack Bashford
Mar 25 at 7:02













@JackBashford Hey man, sry, u r right, I just updated it.

– SPG
Mar 25 at 7:08





@JackBashford Hey man, sry, u r right, I just updated it.

– SPG
Mar 25 at 7:08













Do you really want includes? I'd recommend startsWith

– Bergi
Mar 25 at 8:26





Do you really want includes? I'd recommend startsWith

– Bergi
Mar 25 at 8:26













@Bergi thx, I think startWith is better

– SPG
Mar 26 at 0:30





@Bergi thx, I think startWith is better

– SPG
Mar 26 at 0:30












1 Answer
1






active

oldest

votes


















13














You can do that in following steps:



  • Apply reduce() on the array b


  • During each iteration use filter() on the the array a


  • Get all the items from a which starts with item of b using String.prototype.startsWith()

  • At last set it as property of the ac and return ac




const a = [
id: '1-1-1', name: 'a111' ,
id: '1-1-2', name: 'a112' ,
id: '1-2-1', name: 'a121' ,
id: '1-2-2', name: 'a122' ,
id: '2-1-1', name: 'a211' ,
id: '2-1-2', name: 'a212'
]
const b = ['1-1', '1-2', '2-1']

let res = b.reduce((ac,b) =>

ac[b] = a.filter(x => x.id.startsWith(b));
return ac;

,)
console.log(res)





As suggested by @Falco is the comments that It would be better to scan over the a once as its large. So here is that version.Actually its better regarding performance






const a = [
id: '1-1-1', name: 'a111' ,
id: '1-1-2', name: 'a112' ,
id: '1-2-1', name: 'a121' ,
id: '1-2-2', name: 'a122' ,
id: '2-1-1', name: 'a211' ,
id: '2-1-2', name: 'a212'
]
const b = ['1-1', '1-2', '2-1']


let res = a.reduce((ac,x) =>
let temp = b.find(y => x.id.startsWith(y))
if(!ac[temp]) ac[temp] = [];
ac[temp].push(x);
return ac;
,)

console.log(res)





Note: startsWith is not supported by I.E. So you can create polyfill using indexOf






if(!String.prototype.startWith)
String.prototype.startsWith = function(str)
return this.indexOf(str) === 0









share|improve this answer




















  • 1





    While it is specifically said in the question that the op wants to use es6, and that IE don't support es6 features, I just want to mention that startsWith() don't work in IE (while reduce, filter, and setting a property of an object is totally fine if IE > 9) and if someone wants to do the same thing that startsWith do, they can implment their own with some substring :)

    – Neyt
    Mar 25 at 10:07











  • For big a and small b I would probably go with a.reduce(...) because of locality and only scan over the big array once.

    – Falco
    Mar 25 at 11:13











  • @Falco Thanks for suggestion I updated.

    – Maheer Ali
    Mar 25 at 11:30






  • 1





    @Neyt Thanks for suggestion I updated

    – Maheer Ali
    Mar 25 at 11:33











  • @MaheerAli Thank you - here is a benchmark comparing the two :-) jsbench.me/dfjtoadysr/1

    – Falco
    Mar 25 at 11:47











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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55332644%2fhow-to-merge-and-return-new-array-from-object-in-es6%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









13














You can do that in following steps:



  • Apply reduce() on the array b


  • During each iteration use filter() on the the array a


  • Get all the items from a which starts with item of b using String.prototype.startsWith()

  • At last set it as property of the ac and return ac




const a = [
id: '1-1-1', name: 'a111' ,
id: '1-1-2', name: 'a112' ,
id: '1-2-1', name: 'a121' ,
id: '1-2-2', name: 'a122' ,
id: '2-1-1', name: 'a211' ,
id: '2-1-2', name: 'a212'
]
const b = ['1-1', '1-2', '2-1']

let res = b.reduce((ac,b) =>

ac[b] = a.filter(x => x.id.startsWith(b));
return ac;

,)
console.log(res)





As suggested by @Falco is the comments that It would be better to scan over the a once as its large. So here is that version.Actually its better regarding performance






const a = [
id: '1-1-1', name: 'a111' ,
id: '1-1-2', name: 'a112' ,
id: '1-2-1', name: 'a121' ,
id: '1-2-2', name: 'a122' ,
id: '2-1-1', name: 'a211' ,
id: '2-1-2', name: 'a212'
]
const b = ['1-1', '1-2', '2-1']


let res = a.reduce((ac,x) =>
let temp = b.find(y => x.id.startsWith(y))
if(!ac[temp]) ac[temp] = [];
ac[temp].push(x);
return ac;
,)

console.log(res)





Note: startsWith is not supported by I.E. So you can create polyfill using indexOf






if(!String.prototype.startWith)
String.prototype.startsWith = function(str)
return this.indexOf(str) === 0









share|improve this answer




















  • 1





    While it is specifically said in the question that the op wants to use es6, and that IE don't support es6 features, I just want to mention that startsWith() don't work in IE (while reduce, filter, and setting a property of an object is totally fine if IE > 9) and if someone wants to do the same thing that startsWith do, they can implment their own with some substring :)

    – Neyt
    Mar 25 at 10:07











  • For big a and small b I would probably go with a.reduce(...) because of locality and only scan over the big array once.

    – Falco
    Mar 25 at 11:13











  • @Falco Thanks for suggestion I updated.

    – Maheer Ali
    Mar 25 at 11:30






  • 1





    @Neyt Thanks for suggestion I updated

    – Maheer Ali
    Mar 25 at 11:33











  • @MaheerAli Thank you - here is a benchmark comparing the two :-) jsbench.me/dfjtoadysr/1

    – Falco
    Mar 25 at 11:47















13














You can do that in following steps:



  • Apply reduce() on the array b


  • During each iteration use filter() on the the array a


  • Get all the items from a which starts with item of b using String.prototype.startsWith()

  • At last set it as property of the ac and return ac




const a = [
id: '1-1-1', name: 'a111' ,
id: '1-1-2', name: 'a112' ,
id: '1-2-1', name: 'a121' ,
id: '1-2-2', name: 'a122' ,
id: '2-1-1', name: 'a211' ,
id: '2-1-2', name: 'a212'
]
const b = ['1-1', '1-2', '2-1']

let res = b.reduce((ac,b) =>

ac[b] = a.filter(x => x.id.startsWith(b));
return ac;

,)
console.log(res)





As suggested by @Falco is the comments that It would be better to scan over the a once as its large. So here is that version.Actually its better regarding performance






const a = [
id: '1-1-1', name: 'a111' ,
id: '1-1-2', name: 'a112' ,
id: '1-2-1', name: 'a121' ,
id: '1-2-2', name: 'a122' ,
id: '2-1-1', name: 'a211' ,
id: '2-1-2', name: 'a212'
]
const b = ['1-1', '1-2', '2-1']


let res = a.reduce((ac,x) =>
let temp = b.find(y => x.id.startsWith(y))
if(!ac[temp]) ac[temp] = [];
ac[temp].push(x);
return ac;
,)

console.log(res)





Note: startsWith is not supported by I.E. So you can create polyfill using indexOf






if(!String.prototype.startWith)
String.prototype.startsWith = function(str)
return this.indexOf(str) === 0









share|improve this answer




















  • 1





    While it is specifically said in the question that the op wants to use es6, and that IE don't support es6 features, I just want to mention that startsWith() don't work in IE (while reduce, filter, and setting a property of an object is totally fine if IE > 9) and if someone wants to do the same thing that startsWith do, they can implment their own with some substring :)

    – Neyt
    Mar 25 at 10:07











  • For big a and small b I would probably go with a.reduce(...) because of locality and only scan over the big array once.

    – Falco
    Mar 25 at 11:13











  • @Falco Thanks for suggestion I updated.

    – Maheer Ali
    Mar 25 at 11:30






  • 1





    @Neyt Thanks for suggestion I updated

    – Maheer Ali
    Mar 25 at 11:33











  • @MaheerAli Thank you - here is a benchmark comparing the two :-) jsbench.me/dfjtoadysr/1

    – Falco
    Mar 25 at 11:47













13












13








13







You can do that in following steps:



  • Apply reduce() on the array b


  • During each iteration use filter() on the the array a


  • Get all the items from a which starts with item of b using String.prototype.startsWith()

  • At last set it as property of the ac and return ac




const a = [
id: '1-1-1', name: 'a111' ,
id: '1-1-2', name: 'a112' ,
id: '1-2-1', name: 'a121' ,
id: '1-2-2', name: 'a122' ,
id: '2-1-1', name: 'a211' ,
id: '2-1-2', name: 'a212'
]
const b = ['1-1', '1-2', '2-1']

let res = b.reduce((ac,b) =>

ac[b] = a.filter(x => x.id.startsWith(b));
return ac;

,)
console.log(res)





As suggested by @Falco is the comments that It would be better to scan over the a once as its large. So here is that version.Actually its better regarding performance






const a = [
id: '1-1-1', name: 'a111' ,
id: '1-1-2', name: 'a112' ,
id: '1-2-1', name: 'a121' ,
id: '1-2-2', name: 'a122' ,
id: '2-1-1', name: 'a211' ,
id: '2-1-2', name: 'a212'
]
const b = ['1-1', '1-2', '2-1']


let res = a.reduce((ac,x) =>
let temp = b.find(y => x.id.startsWith(y))
if(!ac[temp]) ac[temp] = [];
ac[temp].push(x);
return ac;
,)

console.log(res)





Note: startsWith is not supported by I.E. So you can create polyfill using indexOf






if(!String.prototype.startWith)
String.prototype.startsWith = function(str)
return this.indexOf(str) === 0









share|improve this answer















You can do that in following steps:



  • Apply reduce() on the array b


  • During each iteration use filter() on the the array a


  • Get all the items from a which starts with item of b using String.prototype.startsWith()

  • At last set it as property of the ac and return ac




const a = [
id: '1-1-1', name: 'a111' ,
id: '1-1-2', name: 'a112' ,
id: '1-2-1', name: 'a121' ,
id: '1-2-2', name: 'a122' ,
id: '2-1-1', name: 'a211' ,
id: '2-1-2', name: 'a212'
]
const b = ['1-1', '1-2', '2-1']

let res = b.reduce((ac,b) =>

ac[b] = a.filter(x => x.id.startsWith(b));
return ac;

,)
console.log(res)





As suggested by @Falco is the comments that It would be better to scan over the a once as its large. So here is that version.Actually its better regarding performance






const a = [
id: '1-1-1', name: 'a111' ,
id: '1-1-2', name: 'a112' ,
id: '1-2-1', name: 'a121' ,
id: '1-2-2', name: 'a122' ,
id: '2-1-1', name: 'a211' ,
id: '2-1-2', name: 'a212'
]
const b = ['1-1', '1-2', '2-1']


let res = a.reduce((ac,x) =>
let temp = b.find(y => x.id.startsWith(y))
if(!ac[temp]) ac[temp] = [];
ac[temp].push(x);
return ac;
,)

console.log(res)





Note: startsWith is not supported by I.E. So you can create polyfill using indexOf






if(!String.prototype.startWith)
String.prototype.startsWith = function(str)
return this.indexOf(str) === 0









const a = [
id: '1-1-1', name: 'a111' ,
id: '1-1-2', name: 'a112' ,
id: '1-2-1', name: 'a121' ,
id: '1-2-2', name: 'a122' ,
id: '2-1-1', name: 'a211' ,
id: '2-1-2', name: 'a212'
]
const b = ['1-1', '1-2', '2-1']

let res = b.reduce((ac,b) =>

ac[b] = a.filter(x => x.id.startsWith(b));
return ac;

,)
console.log(res)





const a = [
id: '1-1-1', name: 'a111' ,
id: '1-1-2', name: 'a112' ,
id: '1-2-1', name: 'a121' ,
id: '1-2-2', name: 'a122' ,
id: '2-1-1', name: 'a211' ,
id: '2-1-2', name: 'a212'
]
const b = ['1-1', '1-2', '2-1']

let res = b.reduce((ac,b) =>

ac[b] = a.filter(x => x.id.startsWith(b));
return ac;

,)
console.log(res)





const a = [
id: '1-1-1', name: 'a111' ,
id: '1-1-2', name: 'a112' ,
id: '1-2-1', name: 'a121' ,
id: '1-2-2', name: 'a122' ,
id: '2-1-1', name: 'a211' ,
id: '2-1-2', name: 'a212'
]
const b = ['1-1', '1-2', '2-1']


let res = a.reduce((ac,x) =>
let temp = b.find(y => x.id.startsWith(y))
if(!ac[temp]) ac[temp] = [];
ac[temp].push(x);
return ac;
,)

console.log(res)





const a = [
id: '1-1-1', name: 'a111' ,
id: '1-1-2', name: 'a112' ,
id: '1-2-1', name: 'a121' ,
id: '1-2-2', name: 'a122' ,
id: '2-1-1', name: 'a211' ,
id: '2-1-2', name: 'a212'
]
const b = ['1-1', '1-2', '2-1']


let res = a.reduce((ac,x) =>
let temp = b.find(y => x.id.startsWith(y))
if(!ac[temp]) ac[temp] = [];
ac[temp].push(x);
return ac;
,)

console.log(res)





if(!String.prototype.startWith)
String.prototype.startsWith = function(str)
return this.indexOf(str) === 0






if(!String.prototype.startWith)
String.prototype.startsWith = function(str)
return this.indexOf(str) === 0







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 25 at 15:19

























answered Mar 25 at 7:04









Maheer AliMaheer Ali

10.6k825




10.6k825







  • 1





    While it is specifically said in the question that the op wants to use es6, and that IE don't support es6 features, I just want to mention that startsWith() don't work in IE (while reduce, filter, and setting a property of an object is totally fine if IE > 9) and if someone wants to do the same thing that startsWith do, they can implment their own with some substring :)

    – Neyt
    Mar 25 at 10:07











  • For big a and small b I would probably go with a.reduce(...) because of locality and only scan over the big array once.

    – Falco
    Mar 25 at 11:13











  • @Falco Thanks for suggestion I updated.

    – Maheer Ali
    Mar 25 at 11:30






  • 1





    @Neyt Thanks for suggestion I updated

    – Maheer Ali
    Mar 25 at 11:33











  • @MaheerAli Thank you - here is a benchmark comparing the two :-) jsbench.me/dfjtoadysr/1

    – Falco
    Mar 25 at 11:47












  • 1





    While it is specifically said in the question that the op wants to use es6, and that IE don't support es6 features, I just want to mention that startsWith() don't work in IE (while reduce, filter, and setting a property of an object is totally fine if IE > 9) and if someone wants to do the same thing that startsWith do, they can implment their own with some substring :)

    – Neyt
    Mar 25 at 10:07











  • For big a and small b I would probably go with a.reduce(...) because of locality and only scan over the big array once.

    – Falco
    Mar 25 at 11:13











  • @Falco Thanks for suggestion I updated.

    – Maheer Ali
    Mar 25 at 11:30






  • 1





    @Neyt Thanks for suggestion I updated

    – Maheer Ali
    Mar 25 at 11:33











  • @MaheerAli Thank you - here is a benchmark comparing the two :-) jsbench.me/dfjtoadysr/1

    – Falco
    Mar 25 at 11:47







1




1





While it is specifically said in the question that the op wants to use es6, and that IE don't support es6 features, I just want to mention that startsWith() don't work in IE (while reduce, filter, and setting a property of an object is totally fine if IE > 9) and if someone wants to do the same thing that startsWith do, they can implment their own with some substring :)

– Neyt
Mar 25 at 10:07





While it is specifically said in the question that the op wants to use es6, and that IE don't support es6 features, I just want to mention that startsWith() don't work in IE (while reduce, filter, and setting a property of an object is totally fine if IE > 9) and if someone wants to do the same thing that startsWith do, they can implment their own with some substring :)

– Neyt
Mar 25 at 10:07













For big a and small b I would probably go with a.reduce(...) because of locality and only scan over the big array once.

– Falco
Mar 25 at 11:13





For big a and small b I would probably go with a.reduce(...) because of locality and only scan over the big array once.

– Falco
Mar 25 at 11:13













@Falco Thanks for suggestion I updated.

– Maheer Ali
Mar 25 at 11:30





@Falco Thanks for suggestion I updated.

– Maheer Ali
Mar 25 at 11:30




1




1





@Neyt Thanks for suggestion I updated

– Maheer Ali
Mar 25 at 11:33





@Neyt Thanks for suggestion I updated

– Maheer Ali
Mar 25 at 11:33













@MaheerAli Thank you - here is a benchmark comparing the two :-) jsbench.me/dfjtoadysr/1

– Falco
Mar 25 at 11:47





@MaheerAli Thank you - here is a benchmark comparing the two :-) jsbench.me/dfjtoadysr/1

– Falco
Mar 25 at 11:47



















draft saved

draft discarded
















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55332644%2fhow-to-merge-and-return-new-array-from-object-in-es6%23new-answer', 'question_page');

);

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







Popular posts from this blog

Solar Wings Breeze Design and development Specifications (Breeze) References Navigation menu1368-485X"Hang glider: Breeze (Solar Wings)"e

Kathakali Contents Etymology and nomenclature History Repertoire Songs and musical instruments Traditional plays Styles: Sampradayam Training centers and awards Relationship to other dance forms See also Notes References External links Navigation menueThe Illustrated Encyclopedia of Hinduism: A-MSouth Asian Folklore: An EncyclopediaRoutledge International Encyclopedia of Women: Global Women's Issues and KnowledgeKathakali Dance-drama: Where Gods and Demons Come to PlayKathakali Dance-drama: Where Gods and Demons Come to PlayKathakali Dance-drama: Where Gods and Demons Come to Play10.1353/atj.2005.0004The Illustrated Encyclopedia of Hinduism: A-MEncyclopedia of HinduismKathakali Dance-drama: Where Gods and Demons Come to PlaySonic Liturgy: Ritual and Music in Hindu Tradition"The Mirror of Gesture"Kathakali Dance-drama: Where Gods and Demons Come to Play"Kathakali"Indian Theatre: Traditions of PerformanceIndian Theatre: Traditions of PerformanceIndian Theatre: Traditions of PerformanceIndian Theatre: Traditions of PerformanceMedieval Indian Literature: An AnthologyThe Oxford Companion to Indian TheatreSouth Asian Folklore: An Encyclopedia : Afghanistan, Bangladesh, India, Nepal, Pakistan, Sri LankaThe Rise of Performance Studies: Rethinking Richard Schechner's Broad SpectrumIndian Theatre: Traditions of PerformanceModern Asian Theatre and Performance 1900-2000Critical Theory and PerformanceBetween Theater and AnthropologyKathakali603847011Indian Theatre: Traditions of PerformanceIndian Theatre: Traditions of PerformanceIndian Theatre: Traditions of PerformanceBetween Theater and AnthropologyBetween Theater and AnthropologyNambeesan Smaraka AwardsArchivedThe Cambridge Guide to TheatreRoutledge International Encyclopedia of Women: Global Women's Issues and KnowledgeThe Garland Encyclopedia of World Music: South Asia : the Indian subcontinentThe Ethos of Noh: Actors and Their Art10.2307/1145740By Means of Performance: Intercultural Studies of Theatre and Ritual10.1017/s204912550000100xReconceiving the Renaissance: A Critical ReaderPerformance TheoryListening to Theatre: The Aural Dimension of Beijing Opera10.2307/1146013Kathakali: The Art of the Non-WorldlyOn KathakaliKathakali, the dance theatreThe Kathakali Complex: Performance & StructureKathakali Dance-Drama: Where Gods and Demons Come to Play10.1093/obo/9780195399318-0071Drama and Ritual of Early Hinduism"In the Shadow of Hollywood Orientalism: Authentic East Indian Dancing"10.1080/08949460490274013Sanskrit Play Production in Ancient IndiaIndian Music: History and StructureBharata, the Nāṭyaśāstra233639306Table of Contents2238067286469807Dance In Indian Painting10.2307/32047833204783Kathakali Dance-Theatre: A Visual Narrative of Sacred Indian MimeIndian Classical Dance: The Renaissance and BeyondKathakali: an indigenous art-form of Keralaeee

Method to test if a number is a perfect power? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)Detecting perfect squares faster than by extracting square rooteffective way to get the integer sequence A181392 from oeisA rarely mentioned fact about perfect powersHow many numbers such $n$ are there that $n<100,lfloorsqrtn rfloor mid n$Check perfect squareness by modulo division against multiple basesFor what pair of integers $(a,b)$ is $3^a + 7^b$ a perfect square.Do there exist any positive integers $n$ such that $lfloore^nrfloor$ is a perfect power? What is the probability that one exists?finding perfect power factors of an integerProve that the sequence contains a perfect square for any natural number $m $ in the domain of $f$ .Counting Perfect Powers