SAPO::Utility.Array->keyValue

This method will return the array keys associated to passed value (if the value exists). It will returns a number if 3rd input param is true. It will returns an array with found associated keys if 3rd param is not set or it is not "true" It will returns false if value not exists in the array.

This is static method.

Syntax

SAPO.Utility.Array.keyValue(string, array, optional)

Compatibility

All browsersYes

Depends

Input Parameters

  • (string) string : Input string
  • (object) array : Input array
  • (boolean) true : Optional if want only the first associated key.

Sample

 http://js.sapo.pt/SAPO/Utility/String/sample/

Example

var aArray = ['orange', 'apple', 'tomato', 'tomato', 'apple'];

alert(SAPO.Utility.Array.keyValue('apple', aArray)); // return (array) [1,4]

alert(SAPO.Utility.Array.keyValue('orange', aArray)); // return (array) [0]

alert(SAPO.Utility.Array.keyValue('apple', aArray, true)); // return (number) 1 

alert(SAPO.Utility.Array.keyValue('kiwi', aArray)); // return (boolean) false

Community feedback

Error: Failed to load processor AddComment
No macro or processor named 'AddComment' found