JSFiddle - React, Tailwind, and code Playground

by seano666

HTML

<div id="content"></div>

JavaScript

var points = [{"name": "tom","color":"green"},{"name":"billy","color":"blue"}];


var newArray = points.filter(function (el) {
  return el.color == "green";
});

for(var i=0;i<newArray.length;i++)
{
    document.getElementById("content").innerHTML += newArray[i].name;
}

//da old browser
if (!Array.prototype.filter) {
  Array.prototype.filter = function(fun /*, thisp*/) {
    var len = this.length >>> 0;
    if (typeof fun != "function")
    throw new TypeError();

    var res = [];
    var thisp = arguments[1];
    for (var i = 0; i < len; i++) {
      if (i in this) {
        var val = this[i]; // in case fun mutates this
        if (fun.call(thisp, val, i, this))
        res.push(val);
      }
    }
    return res;
  };
}