473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Question on execution of an array in Javascript

I have a problem I am working on - any help is appreciated.

An array (noted as arr) contains the numbers 1,2,3,4,5

If the following JS code is run, what numbers will be stored in the array?

Expand|Select|Wrap|Line Numbers
  1. arr[2]++;
  2. arr[1] += arr[2];
  3. arr[3] = arr[3] / arr[2];
Any help is appreciated - I am lost on this one...
Jul 4 '13 #1
5 1333
Xillez
93 64KB
Hi, riplus0623

please post the whole source code...

Expand|Select|Wrap|Line Numbers
  1. var junkData = ["nr. 1", "nr. 2", "nr. 3", "nr. 4"];
  2.  
  3. console.log(junkData[3]);
  4.  
IF you use this setup you see the "console.log(junkData[3]);" part?

The [3] desides which "part" or "slice" of the array it's going to print out.

So in this case it's going to print out only "nr. 3".

Think of an array like this:

var "var name" = [1. "Some Text", 2. "Some Text", 3. "Some Text"];

x(hope this got you on the right track... or at least helped you a bit... )
Jul 4 '13 #2
Rabbit
12,516 Expert Mod 8TB
If you want to know what the values will be, then run the code and output the values.
Jul 5 '13 #3
Xillez
93 64KB
This is the code I used:

Expand|Select|Wrap|Line Numbers
  1. var arr = [1,2,3,4,5];
  2.  
  3. console.log(arr[2]++);
  4. console.log(arr[1] += arr[2]);
  5. console.log(arr[3] = arr[3] / arr[2]);
  6.  
I got 3 outputs:

3
6
1
Jul 5 '13 #4
gits
5,390 Expert Mod 4TB
you should first do all operations and then 'output' the resulting array - then u see what it contains
Jul 5 '13 #5
Thank you everyone for your help. I am new at this and your help is greatly appreciated, especially the explanations of how the array works.
Jul 8 '13 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: BrianP | last post by:
Hi, I have had to invent a work-around to get past what looks like a JavaScript bug, the malfunctioning Perl-like JavaScript array functions including SPLICE() and UNSHIFT(). I have boiled it...
6
by: Flip | last post by:
I'm reading the O'Reilly's Progamming C# book and I have a question about array bounds checking. On page 174, near the top, they show an example where c# does indeed to array bounds checking cause...
3
by: Diana M | last post by:
Hello, I have started my first asp.net application (beginner). I have 2 text boxes on the form that should contain 2 different dates (beginning and end). It would be nice to have 2 small buttons...
2
by: sclemens420 | last post by:
On the PHP site on the preg_replace() function page ( http://us3.php.net/manual/en/function.preg-replace.php ), example 1 uses "@" signs in the regular expression members of the "search" array. On...
2
by: Water Cooler v2 | last post by:
http://www.w3schools.com/js/js_whereto.asp This link is to a JavaScript tutorial on w3schools. The page says that a script put in the HEAD is executed only when called, whereas one put in the...
3
by: zarroba | last post by:
Hi, I'm developing a webpage that is composed by several divs. These divs are supplied by the server depending on the user that made the request. Some of these divs require some javascript...
1
by: Nick | last post by:
Hi, I have a question about array in vc++. I initialized an array from 0 to 480 using memset. and I just realized that in one instance of my code i am putting a value in array position -2, which...
4
by: Markus Ernst | last post by:
Hi While looping through an array I extract all keys on the fly, as in this example: $data = array( array('name' ='Helen', 'age' ='40'), array('name' ='Mark', 'email' ='mark@xyz.com', 'age'...
8
by: linuxfedora | last post by:
Which one is faster or any other better way to do it. I have an array of byte with name: sendBuffer, and i will like to make some thing like that the value started from index of the array in...
7
by: RubyRedRick | last post by:
I bought Crockford's "JavaScript: The Good Parts" yesterday to help build my JavaScript foo. On page 44, he gives an implementation of the curry function: Function.method('curry', function() {...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.