Advertisement
cd62131

Array.map

Dec 28th, 2018
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict'
  2. var data1 = [
  3.   ['A1', 'B1', 'C1', 'Key-A001', 'Key-A002', 'Key-A005', '', ''],
  4.   ['A2', 'B2', 'C2', 'Key-A001', 'Key-A004', '', '', ''],
  5.   ['xx', 'yy', 'zz', 'Key-B002', 'Key-A004', 'Key-X999', 'Key-A002', '']
  6. ]
  7. var data2 = [
  8.   ['val_a1', 'I am valueA1', 'A001'],
  9.   ['val_a2', 'I am valueA2', 'A002'],
  10.   ['val_a3', 'I am valueA3', 'A003'],
  11.   ['val_a4', 'I am valueA4', 'A004'],
  12.   ['val_a5', 'I am valueA5', 'A005'],
  13.   ['val_B_one', 'I am valueB1', 'B001'],
  14.   ['val_B_two', 'I am valueB2', 'B002']
  15. ]
  16. var data3 = data1.map(e => {
  17.   return e.map((e1, i) => {
  18.     var key = e1.match(/\w\d+$/)
  19.     var found
  20.     if (key) {
  21.       found = data2.find(e2 => e2[2] === key[0])
  22.     }
  23.     if (i < 3 || !key || !found) {
  24.       return e1
  25.     }
  26.     return `${found[0]}<br>(${found[2]})`
  27.   })
  28. })
  29. console.log(data3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement