score:-1

use array reduce

    obj =  [ { type: "", numberofquestions:"",  technology:"" }, { type: "1", numberofquestions:"4",  technology:"abcd" }, { type: "", numberofquestions:"6",  technology:"ass" } ];
    
    obj = obj.find(function(item){ if (!(item.type === '' || item.numberofquestions === '' || item.technology === '')){ return item; } });
    
    console.log('array : ', obj);

score:0

first off, dont use = in the object please use : . if you want to check the keys dynamically use this code

    const validatedata = (data) => {
          data.map((object) => {
        object.keys(object).map((innerobj) => {
        if(object[innerobj] === "") {
                  return true;
            } else {
                return false;
            } 

        })

          });
        } 

        var obj =  [{ type: "", numberofquestions:"",  technology:"" }, 
{ type: "1", numberofquestions:"4",  technology:"abcd" }, 
{ type: "", numberofquestions:"6",  technology:"ass" }];

        validatedata(obj);

score:0

you can use filter method

var obj =  [ { type: "", numberofquestions:"",  technology:"" }, { type: "1", numberofquestions:"4",  technology:"abcd" }, { type: "", numberofquestions:"6",  technology:"ass" } ]
obj.filter((a)=>{ return a['type'] == "" ? a : a['numberofquestions'] == "" ? a : a['technology'] == "" ? a : '' }).length > 0 ? true : false;

score:0

this will work regardless of key names (using es6 syntax).

var data =  [ { type: "", numberofquestions:"",  technology:"" }, { type: "1", numberofquestions:"4",  technology:"abcd" }, { type: "", numberofquestions:"6",  technology:"ass" } ]

const checknull = (data) => data.some(item => object.keys(item).some(key => item[key] == ''));

console.log(checknull(data));

score:3

you can use filter function for this, which return the array on the condition

 var container =  [ { type: "", numberofquestions:"",  technology:"" }, { type: "1", numberofquestions:"4",  technology:"abcd" }, { type: "", numberofquestions:"6",  technology:"ass" } ]

    container.filter((a)=>{ return a['type'] == "" ? a : a['numberofquestions'] == "" ? a : a['technology'] == "" ? a : '' }).length > 0 ? true : false;

score:4

you can use array.prototype.some

var array = [...];

function validatedata (array) {
  return array.some(item => item.type === '' || item.numberofquestions === '' || item.technology === '');
}

validatedata(array);

it was es6 solution (with arrow functions).

es5 solution:

function validatedata (array) {
  return array.some(function(item) { 
    return item.type === '' || item.numberofquestions === '' || item.technology === '';
  });
}

Related Query

More Query from same tag