Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9216327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:23:39+00:00 2026-06-18T02:23:39+00:00

I often notice when people split a string of substrings instead of just declare

  • 0

I often notice when people split a string of substrings instead of just declare an array of the necessary strings.

Example in moment.js:

langConfigProperties = 'months|monthsShort|weekdays|weekdaysShort|weekdaysMin|longDateFormat|calendar|relativeTime|ordinal|meridiem'.split('|'),

Example in jQuery

 "Boolean Number String Function Array Date RegExp Object".split(" ")

What is a reason to prefer such way ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:23:41+00:00Added an answer on June 18, 2026 at 2:23 am

    It’s way slower to use the .split, but it has the advantage that the code can be shorter (Less characters):

    var array = 'months|monthsShort|weekdays|weekdaysShort|weekdaysMin|longDateFormat|calendar|relativeTime|ordinal|meridiem'.split('|');
    var array = ['months','monthsShort','weekdays','weekdaysShort','weekdaysMin','longDateFormat','calendar','relativeTime','ordinal','meridiem'];
    

    In this example, the difference isn’t huge, but if you have 100 variables, the difference gets more significant.

    The length added by the delimiter in the split version is 11 + 1 * n, where n is the number of elements, the 11 is for the .split('|')
    For the array version, that’s 2 + 3 * (n - 1), the 2 for the [].

    That means that as soon as you have 6 elements, the .split version is shorter:

    for(var i = 5; i < 8; i++){
        console.log('Elements:', i, 'split:', 11 + (i-1), 'array:', 2 + 3 * (i-1));
    }
    // Elements: 5 split: 15 array: 14
    // Elements: 6 split: 16 array: 17
    // Elements: 7 split: 17 array: 20
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When reading articles about Java threads, I often notice the expression: current thread is
I'm using msys-git and notice I often get strange characters in the output after
Often times I write some SQL like this: string sql = @ -- Multi-line
People often throw around the terms IR, ML, and data mining, but I have
I've currently noticed that many people start using this model very often. Anyways, I
How often do people use objects in PHP? I have noticed it has not
I often notice a few unwanted changes when I review my working copy (with
I've created an example of the problem here: http://jsfiddle.net/jXLSW/ Notice that when you hover
In this example from MS , you'll notice that after we read a byte
I'm new to Javascript, and notice that you don't need to specify an array's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.