文字列の配列からひとつのエントリを削除する

//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);
   
}





SSJS では splice 関数が動作しませんので、このコードで文字列の配列から指定するひとつのエントリを削除できます。

使用方法:

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

var myNewArray = myArray.removeEntry("entry 2");    // これで myNewArray は次の2つのエントリを含むことになります: "entry 1" and "entry 3"

JavaScript (Server)
katoman
July 13, 2015 at 11:01 AM
Rating
0





No comments yetLogin first to comment...