2

I'm trying to create a json object and push it to an array.I want to assign json object's field from an string array.When i write manually (for example {exampleField:"exampleValue"}) is working for me but when I try assign exampleField from an string array it says Unexpected token,expected "," . I think I'm missing very simple thing but i couldnt figure out.

The codes are below

export function excelNull(userReq) {
  var i = 0
  var f = 0
  let values = []
  let headers = Object.keys(userReq[0])
  console.log(headers)
  for (f = 0; f < headers.length; f++) {
    for (i = 0; i < userReq.length; i++) {
      if (isNullOrUndefined(userReq[i][headers[f]])) {
        values.push({
          headers[f]: userReq[i]["__rowNum__"] + 1 + ". satırda " + headers[f] + " boş olamaz"
        })
      }
    }
  }
  return values
}

when i write something different instead of headers[f] it is working. But i wanna dynamic assign from an string array.

So I can get an json object array like [{field1:"val1"},{field2:"val2"}....]

I hope I am clear with my explanation.

Java_User
  • 1,303
  • 3
  • 27
  • 38

0 Answers0