Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

194
Views
Array reduce method is overwriting the first element

below is my function which have reduce method

    getFilters(gridFilters, columnList){
      const filtersArray = [];
      let filterObject = {};
      gridFilters.forEach((ele, i, arr) => {
        filtersArray.push(...arr[i].filters);
      });      
      const _filArr = filtersArray.reduce((acc, {field, operator, value}) => {        
        filterObject['columnName'] = field;   
        filterObject['filterValue1'] = value;
        filterObject['filterOperator1'] = operator;
        filterObject['filterValue2'] = '';
        filterObject['filterOperator2'] = ''; 
        columnList.push(filterObject);    
        return acc;
      }, {});    
      return columnList;

Here, filtersArray will have 2 array elements like'

    Array(2)    
    0:
        field: "objectType"
        operator: "contains"
        value: "lic"
        [[Prototype]]: Object
    1:
        field: "attributeDisplayName"
        operator: "contains"
        value: "date"
        [[Prototype]]: Object
        length: 2
        [[Prototype]]: Array(0)

But after pushing the values to the columnList array, I am seeing the second object (which has attributeDisplayName) is coming for both values. Basically the first object (which has objectType) is getting overwritten with second object in array.

This is how the columnList is getting overwritten

    Array(2)    
    0:
        columnName: "attributeDisplayName"
        filterOperator1: "contains"
        filterOperator2: ""
        filterValue1: "date"
        filterValue2: ""
        [[Prototype]]: Object
    1:
        columnName: "attributeDisplayName"
        filterOperator1: "contains"
        filterOperator2: ""
        filterValue1: "date"
        filterValue2: ""
        [[Prototype]]: Object
        length: 2
        [[Prototype]]: Array(0)

Can some one please suggest what I am doing wrong here. Thanks

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!