Push items in objects from array when matchCreate ArrayList from arrayHow do I check if an array includes an object in JavaScript?Deleting an element from an array in PHPHow to insert an item into an array at a specific index (JavaScript)?Sorting an array of JavaScript objects by propertySort array of objects by string property valueHow to merge two arrays in JavaScript and de-duplicate itemsCopy array items into another arrayHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?
Is Chuck the Evil Sandwich Making Guy's head actually a sandwich?
Doesn't the concept of marginal utility speak to a cardinal utility function?
Why do modes sound so different, although they are basically the same as a mode of another scale?
Pandas transform inconsistent behavior for list
Missing $ inserted. Extra }, or forgotten $. Missing } inserted
Why do motor drives have multiple bus capacitors of small value capacitance instead of a single bus capacitor of large value?
Quick Slitherlink Puzzles: KPK and 123
How were US credit cards verified in-store in the 1980's?
Why is Mitch McConnell blocking nominees to the Federal Election Commission?
Does the telecom provider need physical access to the SIM card to clone it?
To minimize the Hausdorff distance between convex polygonal regions
What happens if you just start drawing from the Deck of Many Things without declaring any number of cards?
Fishing from underwater domes
D Scale Question
What is causing gaps in logs?
How does the search space affect the speed of an ILP solver?
How to have the "Restore Missing Files" function from Nautilus without installing Nautilus?
What is the motivation behind designing a control stick that does not move?
Can authors email you PDFs of their textbook for free?
Why are CEOs generally fired rather being demoted?
Could a simple hospital oxygen mask protect from aerosol poison?
Am I required to correct my opponent's assumptions about my morph creatures?
How could reincarnation magic be limited to prevent overuse?
Why do fuses burn at a specific current?
Push items in objects from array when match
Create ArrayList from arrayHow do I check if an array includes an object in JavaScript?Deleting an element from an array in PHPHow to insert an item into an array at a specific index (JavaScript)?Sorting an array of JavaScript objects by propertySort array of objects by string property valueHow to merge two arrays in JavaScript and de-duplicate itemsCopy array items into another arrayHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have an array and object of items, I want to check each item in that array if its path has that object name, I push it in that object array.
So far this is all good, now if no match found I want to create a new item based on that array item name and push it inside it!
All my attempts ending in duplicated value, I think I need a third object/array I just can't think it anymore
To explain better:
cList =
"rList":
"Significant": [
"Path": "Significant\Significant Charts",
"Name": "Charts"
]
,
;
and
SSList =
value: [
"Name": "Test long name",
"Path": "/someFolder/Test long name",
,
"Name": "Untitled",
"Path": "/Significant/Untitled",
]
;
My current code
for (var cFolder in this.cList.rList)
this.SSList.forEach((ssFile)=>
if(ssFile.Path.indexOf(cFolder) >= 0)
this.cList.rList[cFolder].push(ssFile);
);
The first item in SSList will not be pushed since it doesn't match, I want to create a array and push it to inside rList
var folderName = ssFile.Path.split("/");
this.cList.rList[folderName[1]].push(ssFile);
arrays angular typescript sorting merge
add a comment |
I have an array and object of items, I want to check each item in that array if its path has that object name, I push it in that object array.
So far this is all good, now if no match found I want to create a new item based on that array item name and push it inside it!
All my attempts ending in duplicated value, I think I need a third object/array I just can't think it anymore
To explain better:
cList =
"rList":
"Significant": [
"Path": "Significant\Significant Charts",
"Name": "Charts"
]
,
;
and
SSList =
value: [
"Name": "Test long name",
"Path": "/someFolder/Test long name",
,
"Name": "Untitled",
"Path": "/Significant/Untitled",
]
;
My current code
for (var cFolder in this.cList.rList)
this.SSList.forEach((ssFile)=>
if(ssFile.Path.indexOf(cFolder) >= 0)
this.cList.rList[cFolder].push(ssFile);
);
The first item in SSList will not be pushed since it doesn't match, I want to create a array and push it to inside rList
var folderName = ssFile.Path.split("/");
this.cList.rList[folderName[1]].push(ssFile);
arrays angular typescript sorting merge
add a comment |
I have an array and object of items, I want to check each item in that array if its path has that object name, I push it in that object array.
So far this is all good, now if no match found I want to create a new item based on that array item name and push it inside it!
All my attempts ending in duplicated value, I think I need a third object/array I just can't think it anymore
To explain better:
cList =
"rList":
"Significant": [
"Path": "Significant\Significant Charts",
"Name": "Charts"
]
,
;
and
SSList =
value: [
"Name": "Test long name",
"Path": "/someFolder/Test long name",
,
"Name": "Untitled",
"Path": "/Significant/Untitled",
]
;
My current code
for (var cFolder in this.cList.rList)
this.SSList.forEach((ssFile)=>
if(ssFile.Path.indexOf(cFolder) >= 0)
this.cList.rList[cFolder].push(ssFile);
);
The first item in SSList will not be pushed since it doesn't match, I want to create a array and push it to inside rList
var folderName = ssFile.Path.split("/");
this.cList.rList[folderName[1]].push(ssFile);
arrays angular typescript sorting merge
I have an array and object of items, I want to check each item in that array if its path has that object name, I push it in that object array.
So far this is all good, now if no match found I want to create a new item based on that array item name and push it inside it!
All my attempts ending in duplicated value, I think I need a third object/array I just can't think it anymore
To explain better:
cList =
"rList":
"Significant": [
"Path": "Significant\Significant Charts",
"Name": "Charts"
]
,
;
and
SSList =
value: [
"Name": "Test long name",
"Path": "/someFolder/Test long name",
,
"Name": "Untitled",
"Path": "/Significant/Untitled",
]
;
My current code
for (var cFolder in this.cList.rList)
this.SSList.forEach((ssFile)=>
if(ssFile.Path.indexOf(cFolder) >= 0)
this.cList.rList[cFolder].push(ssFile);
);
The first item in SSList will not be pushed since it doesn't match, I want to create a array and push it to inside rList
var folderName = ssFile.Path.split("/");
this.cList.rList[folderName[1]].push(ssFile);
arrays angular typescript sorting merge
arrays angular typescript sorting merge
asked Mar 28 at 0:30
et3rnalet3rnal
1102 silver badges11 bronze badges
1102 silver badges11 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
One way to do it is to flip your inner and outer loops
let found = false;
this.SSList.value.forEach((ssFile) =>
for (var cFolder in this.cList.rList)
if(ssFile.Path.indexOf(cFolder) >= 0)
found = true;
break;
if (found)
this.cList.rList[cFolder].push(ssFile);
else
folderName = ssFile.Path.split("/");
if (!(folderName[1] in this.cList.rList))
this.cList.rList[folderName[1]] = [];
this.cList.rList[folderName[1]].push(ssFile);
found = false;
);
Just perfect. Thanks, heaps
– et3rnal
Mar 28 at 4:03
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%2f55388464%2fpush-items-in-objects-from-array-when-match%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
One way to do it is to flip your inner and outer loops
let found = false;
this.SSList.value.forEach((ssFile) =>
for (var cFolder in this.cList.rList)
if(ssFile.Path.indexOf(cFolder) >= 0)
found = true;
break;
if (found)
this.cList.rList[cFolder].push(ssFile);
else
folderName = ssFile.Path.split("/");
if (!(folderName[1] in this.cList.rList))
this.cList.rList[folderName[1]] = [];
this.cList.rList[folderName[1]].push(ssFile);
found = false;
);
Just perfect. Thanks, heaps
– et3rnal
Mar 28 at 4:03
add a comment |
One way to do it is to flip your inner and outer loops
let found = false;
this.SSList.value.forEach((ssFile) =>
for (var cFolder in this.cList.rList)
if(ssFile.Path.indexOf(cFolder) >= 0)
found = true;
break;
if (found)
this.cList.rList[cFolder].push(ssFile);
else
folderName = ssFile.Path.split("/");
if (!(folderName[1] in this.cList.rList))
this.cList.rList[folderName[1]] = [];
this.cList.rList[folderName[1]].push(ssFile);
found = false;
);
Just perfect. Thanks, heaps
– et3rnal
Mar 28 at 4:03
add a comment |
One way to do it is to flip your inner and outer loops
let found = false;
this.SSList.value.forEach((ssFile) =>
for (var cFolder in this.cList.rList)
if(ssFile.Path.indexOf(cFolder) >= 0)
found = true;
break;
if (found)
this.cList.rList[cFolder].push(ssFile);
else
folderName = ssFile.Path.split("/");
if (!(folderName[1] in this.cList.rList))
this.cList.rList[folderName[1]] = [];
this.cList.rList[folderName[1]].push(ssFile);
found = false;
);
One way to do it is to flip your inner and outer loops
let found = false;
this.SSList.value.forEach((ssFile) =>
for (var cFolder in this.cList.rList)
if(ssFile.Path.indexOf(cFolder) >= 0)
found = true;
break;
if (found)
this.cList.rList[cFolder].push(ssFile);
else
folderName = ssFile.Path.split("/");
if (!(folderName[1] in this.cList.rList))
this.cList.rList[folderName[1]] = [];
this.cList.rList[folderName[1]].push(ssFile);
found = false;
);
edited Mar 28 at 2:44
answered Mar 28 at 2:35
SaharshSaharsh
6666 silver badges17 bronze badges
6666 silver badges17 bronze badges
Just perfect. Thanks, heaps
– et3rnal
Mar 28 at 4:03
add a comment |
Just perfect. Thanks, heaps
– et3rnal
Mar 28 at 4:03
Just perfect. Thanks, heaps
– et3rnal
Mar 28 at 4:03
Just perfect. Thanks, heaps
– et3rnal
Mar 28 at 4:03
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
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%2f55388464%2fpush-items-in-objects-from-array-when-match%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