skip to Main Content

Between 2 JavaScript Arrays

<script> var array1 = ['2023-04-05','2023-04-06','2023-04-07','2023-04-08']; //array1 var array2 = ['2023-04-06','2023-04-07']; //array2 found1 = array1.find((val, index) => { //find the date in array1 return array2.includes(val); }); $('.show').html(found1); </script> result 2023-04-062023-04-07 how to result like this 2023-04-06, 2023-04-07

VIEW QUESTION

Merge 2 array of objects with different properties – Javascript

I have 2 arrays of objects: array1 = [{"id":1,"cost":200,"qty":56},{"id":2,"cost":100,"qty":16}]; array2 = [{"id":1,"cost":200,"desc":"a good one"},{"id":2,"cost":100,"desc":"a bad one"},{"id":3,"cost":50,"desc":"an okay one"}]; I want to merge them so it looks like this: [{"id":1,"cost":200,"qty":56,"desc":"a good one"},{"id":2,"cost":100,"qty":16,"desc":"a bad one"}]; Please notice the new array has properties…

VIEW QUESTION

How to merge two arrays without using inbuilt/predefined function – Javascript

Input arrays : var arr1 = [{EmpID:'1',Name:'PB',EmpCode:'10001'},{EmpID:'2',Name:'SS',EmpCode:'10002'}]; var arr2 = [{EmpID:'1',Address:'GGN'},{EmpID:'2',Address:'SP-GGN'}]; Expected Output : [{EmpID:'1',Name:'PB',EmpCode:'10001',Address:'GGN'},{EmpID:'2',Name:'SS',EmpCode:'10002',Address:'SP-GGN'}]; I tried below logic function fun(){ var arr1 = [{EmpID:'1',Name:'PB',EmpCode:'10001'},{EmpID:'2',Name:'SS',EmpCode:'10002'}]; var arr2 = [{EmpID:'1',Address:'GGN'},{EmpID:'2',Address:'SP-GGN'}]; var arr3= []; for(var k=0; k < arr1.length; k++){ arr3.push(arr1[k]); }…

VIEW QUESTION
Back To Top
Search