Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. post = [
  2. {postTitle : 'Title1', key = 'key1'},
  3. {postTitle : 'Title2', key = 'key2'}
  4. ]
  5.  
  6. comment = [
  7. {key : 'key1', c: "comment1"},
  8. {key : 'key1', c: "comment2"},
  9. {key : 'key2', c: "commentA"},
  10. {key : 'key2', c: "commentB"},
  11. {key : 'key2', c: "commentC"}
  12.  
  13. ]
  14.  
  15. newPost = [
  16. {
  17. postTitle : 'Title1', key = 'key1', comment: {"comment1", "comment2"}
  18. },
  19. {
  20. postTitle : 'Title2', key = 'key2', comment: {"commentA", "commentB", "commentC"}
  21. }
  22. ]
  23.  
  24. for (var i = 0; i < post.length; ++i) {
  25. for (var j = 0; j < comment.length; j++) {
  26. if (post[i].key === comment[j].key) {
  27. post[i].comment = [];
  28. post[i].comment.push([comment[j].c]);
  29. }
  30. else {
  31. console.log('no comment to add'); }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement