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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:53:05+00:00 2026-05-26T15:53:05+00:00

i want to build an object using this code $(input).bind(keydown,function(e){ var code = (e.keyCode

  • 0

i want to build an object using this code

$("input").bind("keydown",function(e){
 var code = (e.keyCode ? e.keyCode : e.which);
 if (code == 13){
  var guess = $("input").val();
  guess = guess.split(" ");
  var oGuess = {};
  for (var x = 0; guess.length ; x++){
   oGuess[x] = oGuess[x] = {"text": guess[x]};
  }
  $("input").val("");
 }
});

this actually crashes my browsers(latest stable ff and chrome) upon hitting enter. heres the jsfiddle http://jsfiddle.net/kfqJC/1/

i need the object to be something like this

oGuess = {
"1": { "text" : string}
"2": { "text" : string}
...
}

what am I missing here?

  • 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-26T15:53:06+00:00Added an answer on May 26, 2026 at 3:53 pm

    Your loop never terminates. If guess has one element or more, guess.length will always evaluate to true.

    I assume you want

    for (var x = 0; x < guess.length ; x++){
    //              ^^^      
    

    Also, what is this for?

    oGuess[x] = oGuess[x] = {"text": guess[x]};
    

    Just write

    oGuess[x] = {"text": guess[x]};
    

    And if you want the properties start with 1, you have to write

    oGuess[x+1]
    

    thought I don’t see any advantage of using an object over an array in this case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to build a 2 dimensional (non ragged at this point) object array.
I want to build a method which accepts a string param, and an object
I want build a sketch pad app on iPhone, I assume that this type
I have a stream object, and I want to create and output xml using
I want to build a small ORM ( Object Relational Mapping ) framework in
I've got this form, which generates an array as output, and I want to
I want to build a search with four search terms. I'm using Kohana 3.0.7
i want build a photography app with effects . e.g. old images with brown
I want to build a lightweight linux configuration to use for development. The first
I want to build a bot that asks someone a few simple questions and

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.