.poke - macmcmeans/localDataStorage GitHub Wiki

localDataStorage.poke( arrayKeyName, value [, index] )

This is used to place a value onto an existing arrayKeyName, an Array Key, optionally at the index position, as a destructive insert which replaces the original element. When index is omitted, the element is appended to the Array Key by default. When specified, the index is automatically corrected to prevent sparse arrays.

EXAMPLES:

🔹 Existing Array Key called 'course' having value [{'book':'math'}, {'book':'english'}, {'book':'science'}]:

Replace the English book: ● localData.poke( 'course', {'book':'french'}, 2 ); --> [{'book':'math'}, {'book':'french'}, {'book':'science'}]

Append a new book to the array: ● localData.poke( 'course', {'book':'biology'} ); --> [{'book':'math'}, {'book':'french'}, {'book':'science'}, {'book':'biology'}]

The value of the updated arrayKeyName is returned when this method executes.

📝 NOTE: This method is specific to Array Keys and will fail if used on any other key type. This method is related to push and pull. Array Keys use one-based array indices.