Splitting a String into an Associative Array

Author Topic: Splitting a String into an Associative Array  (Read 348 times)

Offline beingchinmayTopic starter

  • Trade Count: (0)
  • Semi-Newbie
  • *
  • Thank You 0
  • Posts: 46
  • Karma: 0
  • Gender: Male
  • I am Chinmay
    • Fat Cutter
Splitting a String into an Associative Array
« on: 09-23-2016, 06:19:03 »
The split() method splits a string by a specified delimiter into a real instance of an Array object. For example:

Code:
Only registered users can see contents. Please click here to Register or Login.
Let’s use the split() method to create a function named
associativeSplit() as a prototype of the String object:


Code:
Only registered users can see contents. Please click here to Register or Login.
Notice the use of an empty function to create an object. At first, the function splits the string via the regular method into a regular array. It then loops through the array, using the next element as the key of an element in the associative array and its following element as the value of the same element in the associative array. Upon completion, the function returns the associative array. The function is then declared as a prototype of the built-in String object, applying to all strings. Now take a look at an example .


Code:
Only registered users can see contents. Please click here to Register or Login.


 

Related Topics

  Subject / Started by Replies Last post
0 Replies
540 Views
Last post 12-21-2015, 02:27:50
by chinmay.sahoo
0 Replies
356 Views
Last post 02-10-2016, 01:36:24
by chinmay.sahoo
0 Replies
332 Views
Last post 03-29-2016, 02:42:10
by chinmay.sahoo
1 Replies
885 Views
Last post 05-30-2016, 21:09:23
by ngomaichi
0 Replies
875 Views
Last post 06-08-2016, 07:32:24
by chinmay.sahoo