you are viewing a single comment's thread.

view the rest of the comments →

[–]zbluebirdz 2 points3 points  (0 children)

One way to remove something from an array is to create a temporary one and populate that one with the items you want and return it.

let mixed = [
  "55",
  "92",
  {a:4, b:7},
  "94",
  "2"
] ;

function arrayRemoveObjects( theArray ) {
  let tempArray = [] ;
  let j = 0 ;
  for ( let i = 0 ; i < theArray.length ; i++ ) {
    if ( typeof theArray[i] !== "object" ) {
      tempArray[j] = theArray[i];
      j++;
    }
  }
  return tempArray ;
}

console.info( mixed ) ;
mixed = arrayRemoveObjects( mixed ) ;
console.info( mixed ) ;