The nested arrays in JavaScript produce different results when viewed in developer tools compared to when they are printed using toString()

There is a strange issue with the nested array in my current project that I need help with.

When I log the nested array in console.log as individual values, it displays correctly.

For example:

console.log("Array: " + arr) //Array: 0,0,0,0,0,0,0,1

However, when I log the array as an object, the output values are completely different. Upon expanding it on Chrome's developer tools, this is what I see:

console.log(arr)//(2)[Array(2), Array(2)]
0: [2][1,4]
1: [2][0,1]

Sometimes JavaScript/developer tools can be unpredictable, so I need guidance from the community.

I am confident there are no pointer issues because the two print statements happen immediately after each other and only involve simple operations like incrementing by +1 on the main nested array.

I searched online but found no similar cases to mine, hence why I'm reaching out here. This may be the best example I can provide, and anything else may not add much value to this discussion.

Another strange thing I noticed concerning the same matrix object is that when I try to access a specific element e.g. arr[0][0][0], the retrieved value is unexpected.

Thank you for your assistance, and if there are no known issues or considerations regarding either the developer tools or JavaScript, I will close this query.

Update: When expanded in the developer tools, this line:

https://i.sstatic.net/vp7cd.png

Returns a whole new set of values. The initial 14 somehow becomes 67 upon expansion. https://i.sstatic.net/LUO7G.png

Answer №1

"List: " + list

By concatenating list.toString(), a string is created (this is the mechanism behind the use of the + operator). The toString() method for arrays puts together the individual elements, separated by commas. Consequently, if your array has subarrays, they will be recursively flattened.

console.log(list)

This sends the actual array to console.log(), which handles objects differently when displaying them.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to simulate the Enter key press event for a text area using Angular 7

I've implemented a feature that allows users to type something and then press the submit button, at which point the cursor should move to the next line. If the user types some words and presses the Enter key, the cursor should also shift to the next l ...

Using JavaScript on mobile devices to stream a camera feed to a server

Currently, we are developing an application that requires streaming video recordings to a server. The process flow is as follows: 1) Open a website and activate the primary camera 2) Commence streaming of the camera video to the server 3) Complete the task ...

Navigate through FAQ items with sliders using Owl Carousel 2 - Easily switch between different chapters

Exploring the creation of a FAQ section with individual carousels for each item. My primary objective is for the carousel to transition to the next chapter when advancing beyond the last slide (backwards navigation would be a future enhancement). I'v ...

show certain DIVs based on the URL

Is it possible to dynamically display different sections based on the URL? My event website has 3 subevents, and I'd like to show the date of each event in the navigation bar for their respective URLs. <div id="us" class="us-web-date">&nbs ...

Record of Recaptcha actions is not showing up in the reports

My method of running the recaptcha script is as follows: let data = { action: 'homepage' }; grecaptcha.ready(() => { grecaptcha.execute('RECAPTCHASITEKEY', data).then((token) => { recaptcha_token = token; }); ...

utilizing services across multiple controller files

Service - optionService.js controllers - app.js & welcomeCtrl.js & otherCtrl.js app.js var app = angular.module('mainapp', ['mainapp.welcome','optionServiceModule']); app.controller('mainappCtrl', functio ...

Having trouble converting JSON into a JavaScript object

I am encountering an issue with my HTML box: <span>Select department</span><span> <select id="department" onchange="EnableSlaveSelectBox(this)" data-slaveelaments='{"a": 1, "b": "2& ...

Guide on extracting matching values from one object based on the properties of another object

Looking to iterate through the object below and extract author names based on matching titles with other objects. The goal is to create a new object for easier management. business1 { "type": "FeatureCollection", "features": [ { ...

Error message related to the callback type issue in Node.js with the http.createServer

Having recently embarked on my journey with node.js, I delved into various tutorials and encountered a stumbling block while attempting to refactor some code. The tutorial that caught my attention and led me to this hiccup can be found here: http://www.tu ...

Nested JSON array is being shown as [Object Object] within a TextField

I am facing an issue with mapping two sets of JSON data, which I will refer to as Set 1 and Set 2. In Set 1, the data (named sizingData) is being mapped to text fields using the following function: const fillTextField = () => { let result = []; ...

Node.js encountering an empty array from an API request

In the 'product.js' file, there seems to be an issue with the API call '/achaar/products/1'. The value of val is empty when logging it in the console. Other API calls like '/achaar/products' are functioning correctly, but spec ...

"Utilize AJAX to submit the value of the text box input from a jQuery slider when the Submit Button

Whenever I adjust the sliders, the value is shown in an input textbox. However, when I move the slider and check the values echoed from the textboxes on another PHP page, they are always displaying as 0. Even after clicking the submit button, it still echo ...

Divide the array in Ruby

Could you offer assistance with a problem I'm facing? I currently have an array from the database that looks like this: str = Hiring::Tag.all Hiring::Tag Load (0.1ms) SELECT `hiring_tags`.* FROM `hiring_tags` => [#<Hiring::Tag id: 1, name: ...

Can jQuery script be used within a WordPress page for inline execution?

Can jQuery be executed in the middle of a page (inline)? I attempted to run the following code within a custom WordPress template.... <script type="text/javascript"> jQuery(document).ready( function() { jQuery(".upb_row_bg").css("filter","blur(30 ...

What is the process for bundling a separate JavaScript file with Webpack5?

I am new to the world of webpack. I have 2 javascript files and I want to designate one as the main entry file. However, for the other file, I only want to include it in specific files. For example, looking at the file structure below, main.js is my entr ...

`"Unable to execute the 'ng build --env=prod' command"`

I have a JavaScript website that I need to rebuild with some changes I made. In order to build the application, I was instructed to run this command from the source files directory: ng build –env=prod However, when I try to do so, I keep encountering t ...

Encountering a problem with the persistent JavaScript script

I have implemented a plugin/code from on my website: Upon visiting my website and scrolling down, you will notice that the right hand sidebar also scrolls seamlessly. However, when at the top of the screen, clicking on any links becomes impossible unless ...

jQuery AJAX calls are unsuccessful, while NodeJS requests are running smoothly

I am experiencing an issue with a RESTful web service that returns JSON. Interestingly, a NodeJS command line test application is able to retrieve the JSON data without any problems: Successful NodeJS Application: var request = require("request"); var bt ...

Tips for retrieving hash elements from a hash array by referencing the value of the array

input_hash = [{"id"=>"123", "name"=>"ashly"}, {"id"=>"73", "name"=>"george"}, {"id"=>"175", "name"=>"nancy"}, {"id"=>"433", "name"=>"grace"}] check = ["73", "175"] output => "george, nancy" There seems to be a way to use &apos ...

Inadvertent scroll actions causing unexpected value changes in Material UI sliders

I am currently working on a React application that utilizes Material UI, with slider components integrated throughout the interface. However, I have encountered an issue when using a touch screen device - unintentional changes to the slider values occur wh ...