Splitting a String into an Associative Array

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

Offline beingchinmayTopic starter

  • Trade Count: (0)
  • Jr. Member
  • **
  • Thank You 0
  • Posts: 68
  • 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
618 Views
Last post 12-21-2015, 02:27:50
by chinmay.sahoo
0 Replies
455 Views
Last post 02-10-2016, 01:36:24
by chinmay.sahoo
0 Replies
424 Views
Last post 03-29-2016, 02:42:10
by chinmay.sahoo
0 Replies
1135 Views
Last post 06-08-2016, 07:32:24
by chinmay.sahoo
0 Replies
69 Views
Last post 01-21-2017, 06:45:26
by Ben_Gunn