This topic contains 0 replies, has 0 voices, and was last updated by lw1 6 years, 5 months ago.

  • Author
    Posts
  • #17888

    lw1

    Hi All,

    If you tried to use find or findIndex in your server-side suitescript code and came up short, ie got an error like “TypeError: Cannot find function find in object ” or “TypeError: Cannot find function findIndex in object ” I’ll show you how to fix this and add modern array functionality to NetSuite’s server-side javascript engine.

    Just add this function to your script or library and call it:

    Code:
    //fix netsuite javascript engine
    //adds modern array functionality
    function FixNetSuiteJavaScript() {
    // https://tc39.github.io/ecma262/#sec-array.prototype.find
    if (!Array.prototype.find) {
    Object.defineProperty(Array.prototype, ‘find’, {
    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 >> 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 This is a cached copy. Click here to see the original post.

You must be logged in to reply to this topic.