Hide Table of Contents
esri/dijit/util
esri/layer/pixelFilters
esri/process
esri/workers
Object: esri/lang

require(["esri/lang"], function(esriLang) { /* code goes here */ });

Description

(Added at v3.8)
Utility methods for working with strings, arrays and objects.

When coding legacy (non-AMD) style, there is no need to require the module. All methods and properties are available in the namespace. For example, esri.filter().

Samples

Search for samples that use this class.

Methods

NameReturn typeSummary
filter(object, callback, thisObject?)ObjectCreates a new object with all properties that pass the test implemented by the filter provided in the function.
isDefined(value)BooleanReturns true when the value is neither null or undefined.
stripTags(value)Object | StringStrips HTML tags from a String or Object.
substitute(data, template?, first?)StringA wrapper around dojo.string.substitute that can also handle wildcard substitution.
valueOf(array, value)ObjectIterates through the argument array and searches for the identifier to which the argument value matches.
Method Details

filter(object, callback, thisObject?)

Creates a new object with all properties that pass the test implemented by the filter provided in the function.
Return type: Object
Parameters:
<Object> object Required Object to filter.
<Function> callback Required Function or string implementing the filtering.
<Object> thisObject Optional Optional object used to scope the call to the callback.
Sample:
require([
  "esri/lang", "dojo/dom", ... 
], function(esriLang, dom, ... ) {
  function showResults(results) {
    var filterFunction = function(value) {
      if ((value !== ' ') & (Number(value) !== 0)) {
        return true;
      };
    };

    var filteredResults = esriLang.filter(results.features[0].attributes, filterFunction);
    var s = "";
    for (att in filteredResults) {
      s = s + "<b>" + att + ":</b>  " + filteredResults[att] + "<br />";
    };
    dom.byId("info").innerHTML = s;
  };
  ...
});

isDefined(value)

Returns true when the value is neither null or undefined. Otherwise false.
Return type: Boolean
Parameters:
<Object> value Required The value to test. 

stripTags(value)

Strips HTML tags from a String or Object. This method modifies the Object used as input and does not return a new value. If a String is used as input, a new String is returned. (Added at v3.13)
Return type: Object | String
Parameters:
<Object | String> value Required Object or String to be stripped of HTML tags.
Sample:
require(["esri/lang", "dojo/domReady!"], function(esriLang) {
  var myobj = {
    name: "<b>Jane</b>",   //myobj.name = "<b>Jane</b>"
    last: "Doe",
    age: "30"
    };
          
  esriLang.stripTags(myobj);
  console.log(myobj);   //myobj.name = "Jane"
});

substitute(data, template?, first?)

A wrapper around dojo.string.substitute that can also handle wildcard substitution. A wildcard uses the format of ${*}. If no template is provided, it is assumed to be a wildcard. This method is useful if you are not using Graphic or an InfoTemplate, but you want to embed result values in HTML, for example.
Return type: String
Parameters:
<Object> data Required The data object used in the substitution.
<String> template Optional The template used for the substitution. Can be any valid HTML. If no template is included, the wildcard template is used.
<Boolean> first Optional When true, returns only the first property found in the data object. The default is false.
Sample:
Require this method:
require(["esri/lang", ... ], function(esriLang, ... ) { ... });
Example 1: no wildcard is included but is assumed.
esriLang.substitute({state_name: "Arizona", state_capital: "Phoenix"});
Returns: state_name = Arizona state_capital = Phoenix

Example 2: no wildcard is included and only the first property is displayed.
esriLang.substitute({state_name: "Arizona", state_capital: "Phoenix"},null,true);
Returns: state_name = Arizona

Example 3: a template is included for display.
esriLang.substitute({state_name: "Arizona", state_capital: "Phoenix"},"The capital of ${state_name} is ${state_capital}.");
Returns: The capital of Arizona is Phoenix.

valueOf(array, value)

Iterates through the argument array and searches for the identifier to which the argument value matches. Returns null if no matching identifier is found.
Return type: Object
Parameters:
<Array> array Required The argument array for testing.
<Object> value Required The value used in the search. If the value is a String, the value is case sensitive.
Sample:

Example 1:

require([
  "esri/lang", ... 
], function(esriLang, ... ) {
  esriLang.valueOf([firststring: "Oregon", secondstring: "Washington"], "Washington");
  ...
});

Returns: secondstring

Example 2:

require([
  "esri/lang", ... 
], function(esriLang, ... ) {
  esriLang.valueOf([firststring: "Oregon", secondstring: "Washington"], "Virginia");
  ...
});

Returns: null