Javascript string include method Object doesn't support this property or method

Oh Opus Fraternity
What am I doing wrong with this string.include method?
I know this seems to be more a JS question then Opus.... cannot find anyting on the web.
Scraped this sample snippet off one of my hits actually...

function OnClick(clickData)
{
	// --------------------------------------------------------
	DOpus.ClearOutput();
	// --------------------------------------------------------

	var str = "Welcome to GeeksforGeeks.";
	var check = 0
    DOpus.Output("010 check     :" + check);
    check = str.includes("Geeks");
    DOpus.Output("020 check     :" + check);

	// --------------------------------------------------------
}

JScript is an old version of JavaScript and its string object is missing some of the newer methods. This is likely one of them.

1 Like

Thanks Leo.
Might anyone know an online resource that constitutes an authorative source for the version of jscript in use on DOpus?
I have looked

  1. DOpus > Help > About
  2. I had reason to look in the jscript code in this post Script to perform multiple Regular Expressions.
    I thought that in the comments there that references to some microsoft or other URL existed but not there I must be mistaken. In that same post is a sample script to execute multiple regular expression file renames. It uses the
    str.toLowerCase(); and
    str.replace()
    methods in that code obviously successfully.
  3. I have tried these also no joy
    str.find(); and
    str.Find()

Any help much appreciated

I've been looking but it seems like Microsoft don't have an official reference of their own to JScript (they have basically dropped all support for it themselves).

From what I can gather it was based on the official ECMAScript 3.0 standard, which is described here:

Looking at that, there's no find() or includes() method, but there is indexOf() which might do what you want:

1 Like

Thanks @Jon
In the mean time using this microsoft link I have got this working see below.
What I am looking to understand now is the format of the substring field.
The URL above has the following definition:

  • rgExp
    Required. An instance of a Regular Expression object containing the regular expression pattern and applicable flags.

Watch this space....

function OnClick(clickData)
{
	// https://learn.microsoft.com (See hyperlink in  post)
	// 2023-03-21 Worked
	//
	// --------------------------------------------------------
	DOpus.ClearOutput();
	// --------------------------------------------------------

    var src = "0123456789Marker xxxxxxxx";
    // Create regular expression pattern.
	var pos = 0
    var re = /Marker/i;
    // Search the string.
    DOpus.Output("010 pos     :" + pos);
    var pos = src.search(re);
    DOpus.Output("020 pos     :" + pos);

	// --------------------------------------------------------
}

1 Like

@slouw Another good resource in my opinion is the W3Schools Javascript Tutorial. There is not a 100% correlation with DOpus' JavaScript but it is very close. I found it very helpful when I first started with JS and have continued to use it a reference ever since.

1 Like

In this case you are looking for polyfills (meaning something like filling up methods which are not present in your js version).
Eg String.includes() | The Vanilla JS Toolkit

if (!String.prototype.includes) { //checking if method is present
	String.prototype.includes = function(search, start) {
		'use strict';

		if (search instanceof RegExp) {
			throw TypeError('first argument must not be a RegExp');
		}
		if (start === undefined) { start = 0; }
		return this.indexOf(search, start) !== -1; //this is what you are actually looking for
	};
}

So instead of

str.includes("Geeks")

use

str.indexOf("Geeks") != -1

Thanks @Felix.Froemel
There is a lot for me to take in with that interesting post......
I will study it thanks again

BTW saw this post here seems quite authoritive about the JavaScript version used by DOpus....
Version of javascript used by DOpus

Here are the Windows Script Host / ActiveScript Reference Manuals