Remove an entry from an array of strings

//remove an entry (string) from a list of strings
Array.prototype.removeEntry = function( entry:String ) {

	if ( @IsNotMember(entry, this)) {
		return this;
	var res = @Trim( @Replace(this, entry, "") );
	return (typeof res == "string" ? (res.length==0 ? [] : [res]) : res);

The splice function doesn't work in SSJS. This code will extend the array object in SSJS with a new method that will remove a specific entry from a array of strings.


var myArray = ["entry 1", "entry 2", "entry 3"];

var myNewArray = myArray.removeEntry("entry 2");    // myNewArray now contains 2 entries: "entry 1" and "entry 2"

JavaScript (Server)
Mark Leusink
January 5, 2012 6:02 AM

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.

1 comment(s)Login first to comment...
Steve Smillie
(at 15:46 on 24.04.2013)
I thought I was going crazy, until I realized that splice on an a array in SSJS was the problem.
This worked well to remove from an array.