Passing Arrays

Can you pass an array directly into a cookie file, or do you have to convert it to a string first? If you have to convert it to a string (using the toString or join methods) is there a way to do so without JavaScript forcing delimiters or separators into the string? For example, myArray.toString() will force commas to separate the elements of the array. “101101” becomes “1,0,1,1,0,1”. Is there a parameter I can place in the ()’s so the string returned is “101101”?

You don’t have to do any conversion. When you assign the array to the cookie (or any string) it will be automatically converted into a list separated by commas. However, if any of the array elements contain a comma (,) as part of their value you’ll have problems later figuring out which commas belong in the array values and which are separators. So, if you want more control when converting an array into a string, the join method is your best bet. This method takes one parameter and uses it as the separator between each array element as it is added to the string. Although spaces, commas, and dashes are common separators, you can forego a separator completely by specifying an empty string (“”) as the parameter. So a command like myarray.join(“”) will create a string with nothing between the array elements

The result is 
Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a