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 7161881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:38:32+00:00 2026-05-28T13:38:32+00:00

I want to split a string by no delimiter (effectively splitting it by each

  • 0

I want to split a string by no delimiter (effectively splitting it by each character), then index into an object in alphabetical order. I want it to utilize jQuery.

Here is my attempt, but this splits into an array, and elements are accessed by square brackets (obj_to_chars[0], obj_to_chars[1], etc), but I want to be able to access elements by using the dot notation, like so: obj_of_chars.a, obj_of_chars.b, etc.

var str = 'The quick brown fox jumps over the lazy dog.';
var obj_of_chars = {};
obj_of_chars = str.split("");
console.log(obj_of_chars);
// what I have: [ "T", "h", "e", " ", "q", "u", "i", "c", "k", " ", "b", "r", "o", "w", "n", " fox", " ", "j", "u", "m", "p", "s", " ", "o", "v", "e", "r", " ", "t", "h", "e", " ", "l", "a", "z", "y", " ", "d", "o", "g", "." ]
// what I want: { a: "T", b: "h", c: "e", d: " ", e: "q", ..., aa, ab, ... }

EDIT: The solution should allow more than 26 characters in the object. (sorry to those who already wrote a piece of code, just realized I needed more than 26 characters)

  • 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-05-28T13:38:33+00:00Added an answer on May 28, 2026 at 1:38 pm

    Here’s one way to do it:

    var input = "Hello world";
    var output = {};
    for(var i = 0; i < input.length; ++i) {
        var prop = String.fromCharCode(97 + i); // 97 = ASCII code for "a"
        output[prop] = input.charAt(i);
    }
    

    If the length of the input string is more than 26, this code will spill over the alphabet and start using non-alpha characters as keys. Modify the expression that sets prop accordingly if you want to avoid this.

    Update: Here’s how to continue the alphanumeric property name scheme indefinitely:

    var input = "Hello worldHello worldHello worldHello worldHello worldHello world";
    var output = {};
    var name = ['a'];
    for(var i = 0; i < input.length; ++i) {
        output[name.join("")] = input.substr(i, 1);
        for (var j = name.length - 1; j >= 0; --j) {
            if(name[j] != 'z') {
                name[j] = String.fromCharCode(name[j].charCodeAt(0) + 1);
                break;
            }
            else {
                name[j] = 'a';
                if(j == 0) {
                    name.unshift('a');
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to split a string using a delimiter, for example split "004-034556" into
I want to split a string like this: abc//def//ghi into a part before and
I want to split a string like 001A into 001 and A
I have a string ABCD:10,20,,40;1/1;1/2,1/3,1/4 I want to split the string into the following
Really simple problem: I want to split a connection string into its keyword /
What if I want to split a string using a delimiter that is a
My question is that I want to split string in java with delimiter ^
I want to split a string with ? as the delimiter. str.split(?)[0] fails.
I am trying to split/explode/preg_split a string but I want to keep the delimiter
String.Split is convenient for splitting a string with in multiple part on a delimiter.

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.