Finding Index of a particular value in array [Array of Objects]

I would like to know the best way to find the index of an element in an array of objects with a certain value. The elements are objects, so to my knowledge, indexOf will not work.
Here is a generalization of the data:
Code:
var myArray = [
    {name: 'Jim',
    value: 'foo'},

    {name: 'Bob',
    value: 'bar'},

    {name: 'Pete',
    value: 'foobar'}
];

I saw the findIndex method for arrays, so I initially wrote this.

Code:
var index = myArray.findIndex(function(i) {return i.value === 'bar'});
if (index >= 0) {
    console.log('bar is found at index ' + index);
}

It appears that the findIndex method is not supported in RPG Maker MV !
I get 'undefined is not a function' error messages in the console (v1.5.1).

Of course, I could write this as a standard 'for' loop.
Code:
var index = -1;
for (var i = 0; i < myArray.length; i++) {
    if (myArray[i].value === 'bar') {
        index = i;
    }
}
if (index >= 0) {
    console.log('bar is found at index ' + index);
}

My questions:
  • Is there a more elegant way to accomplish this that is allowed in RMMV?
  • Do we know when RMMV will support this method? (ECMAScript 6)
I can answer the second question. Not the first one, since I'm not a pro in associative arrays. I use objects to store data instead of arrays.

ES6 is supported in the open beta of 1.6.0. If you have a steam version, you can participate in the betatesting too, although first you need to enter the article inside MV improvement boards. You can't miss that.
https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Array/findIndex

here the polyfill
Create a new .js , call it Mypolyfill.js
add this, and add top of plugin manager.
PHP:
// https://tc39.github.io/ecma262/#sec-array.prototype.findIndex
if (!Array.prototype.findIndex) {
  Object.defineProperty(Array.prototype, 'findIndex', {
    value: function(predicate) {
     // 1. Let O be ? ToObject(this value).
      if (this == null) {
        throw new TypeError('"this" is null or not defined');
      }

      var o = Object(this);

      // 2. Let len be ? ToLength(? Get(O, "length")).
      var len = o.length >>> 0;

      // 3. If IsCallable(predicate) is false, throw a TypeError exception.
      if (typeof predicate !== 'function') {
        throw new TypeError('predicate must be a function');
      }

      // 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
      var thisArg = arguments[1];

      // 5. Let k be 0.
      var k = 0;

      // 6. Repeat, while k < len
      while (k < len) {
        // a. Let Pk be ! ToString(k).
        // b. Let kValue be ? Get(O, Pk).
        // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
        // d. If testResult is true, return k.
        var kValue = o[k];
        if (predicate.call(thisArg, kValue, k, o)) {
          return k;
        }
        // e. Increase k by 1.
        k++;
      }

      // 7. Return -1.
      return -1;
    }
  });
}

you can also add some plyfill from
http://underscorejs.org/#findIndex

of other cool modern JS utility library here from tjmehta, with a lot of polyfill
https://github.com/tjmehta/101
Awesome, thanks both.
I was aware of the next version of RMMV but somehow missed that the testing is actually open to the community. I need to think some more if I want to try it or wait for the official release.

If I'm understanding the polyfill correctly, I can add it now but I can get rid of it once the engine itself is updated to ES6.
yes, ES6 have some new method, most are just basic code to save your time.

example Range, its not existe in basic code. but you can add it to Array.prototype, and now you will can call it on array
PHP:
        Array.prototype.range = function(begin, end) {
            if (typeof end === "undefined") {  end = begin; begin = 0; };
            var result = [], modifier = end > begin ? 1 : -1;
            for ( var i = 0; i <= Math.abs(end - begin); i++ ) { result.push(begin + i * modifier); };
            return result;
        };
these much faster than writing this code to each faith.
Separate your improvements into a separate file to keep it clean.
i would be very surprised that rmmv offer ES6!.
devs will all have to write the software.
At this point, rather release a new software!!!

Original thread: https://forums.rpgmakerweb.com/threads/finding-index-of-a-particular-value-in-array-array-of-objects.88968/