this string will evaluate to a 2D array if I do this:var array = eval(string);But eval is not very safe.Is there a way to achieve the same effect (turn that string into 2d array) without using eval function?And I have no control over what string I am given, so will have to process this kind of a string =Right now I am thinking of writing a custom function which will split the string and then split again etc, but is there already something that can do this job?
I have a three tier nested array, used to define a map for a javascript game, and can be edited within the web page. Is there a way I can generate a visible copy of this array that I can then c&p into a file? I think the best solution would be to write into a popup window (this popup would be purely for map development use, so I don't feel worried by popup blockers, as only myself would be seeing the popup). However, I have no idea how to:
a) create the string in a form that a html parser can display as ready-formatted javascript code
So i've written up the code to do a lightbox esque overlay image gallery. everything is working smooth and fine. The only concern is that I have the following:
lets say that I have a page that has multiple galleries. Obviously I would have to make each literal array with the gallery data different names, ex:
obviously "galVariable" would be undefined... as i'm trying to get "_gallery2.images" but trying to use "galVariable" to point to "_gallery2"
I'm familiar with solving a problem like this in PHP, not so much javascript. is there a JS function that can be used to ensure that it's using whatever "galVariable" equals to, and then that array's content is? Or is there a different way to go on about this.
What I'm trying to do, I think, is to use elements of an array as a part of an object. Here's a lil' code snippet:
Code:
I'm trying to insert each of the elements of the katMusik-array into the checked-line, thus checking the checkboxes with those names. However, it doesn't seem to work.
I am getting a string with the value of the clicked button from an array and some other select field values that are listed in the same set of mysql results as the clicked button.At the end of the script the page is redirected to in the script mentioned page with following string:process.php?value=1&bs=2&ad=3&ns=4&wt=5&in=6 Is it possible to make locationstring variable global and in a single line in order to be able to use the full string in other scripts or is there another solution.
I'm trying to turn an associative array key into a string. I know I can do that in php with a foreach loop like foreach ($array as $key => $value) and then I can do whatever I want with the key. I want to be able to loop through a javascript array using a for in loop and test to see if the key matches part of the name attribute of some inputsIs there a way to do this? I looked online and I found a way to turn a string into a variable name but not the reverse
The values I have in variable "tables".I want to create variable list which takes values from "tables".Than I want to split this, and put each value in to new array: I've started with:
var list = "tables"; var listArray = list.split("|"); for(i=0; i < listArray.length;i++)[code].....
I'm not entirely familiar with the norms and standard libraries of JavaScript so if the answer to this is yesterday's news, please ignore.
I'm trying to write a simple text formatting function to make headings proper case -- i.e. first letter of words capitalized.
I first tried this...
function inProperCase(s) { var result, i, k; i = 0; result = s.toLowerCase(); while ((k = result.indexOf(' ', i)) -1) { if (k - i 0) { result[i] = result[i].toUpperCase(); } i = k + 1; } if (result.length - i 1) { result[i] = result[i].toUpperCase(); } return result; }
...but it didn't work. To my amazement, you cannot set a character in a string by accessing that character with an index, like so:
s[i] = ch;
Must be because JavaScript strings are "Immutable" or "EtchedInStone" or something. (Just kidding, no flames, please. I'm sure it is more efficient.)
The only thing I could come up with was this (with some details, like the "compound" while predicate, modified into a more readable form after being called a "C-bigot" by a friend :)) which seems pretty heavy-handed with all the string slicing and concatting:
function inProperCase(s) { var result = s.toLowerCase(), i = 0, k = result.indexOf(' ', i); while (k -1) { if (k - i 0) { result = result.substring(0, i) + result[i].toUpperCase() + result.substring(i+1, result.length); } i = k + 1; k = result.indexOf(' ', i); } if (result.length - i 1) { result = result.substring(0, i) + result[i].toUpperCase() + result.substring(i+1, result.length); } return result; }
You call this as...
inProperCase(" madam i'm adam ");
...and you get...
" Madam I'm Adam "
Any suggestions for making this a bit more elegant?
BTW You may point me to a "library" with a super-efficient implementation of this function, but that is not the point. My issue is, how do we update single characters in a string (or single items in an array) in JavaScript? Is it something like...
I've searched on the form and found answers but I cant get it fix for me. want to make a form with multiple rows with checkboxes. Firt I did it in PHP and it worked but I want to use Jquery. How can I get the checked checkboxes to a string?It thought it would be something like this (found it on this site):
var test = $(':checkbox').map(function() { return this.id; }).get().join(',');
I am trying to search an array for a string and then if it is found alert it. I have found examples of how to iterate the array and how to use .IndexOf to return a true false statement as to whether the array includes the string, but i don't know what to do after that and how to display the string if its found.
Given a JavaScript "array" (ok, so really they are "objects" but it's being treated as an array...) in the format
HTML Code: var patient_code = "0" var header_id = "1"; var question_id = "1000"; fake_data_array["patients"][patient_code][header_id][question_id] HTML Code: var fake_data_array = new Array(); fake_data_array["heading_information"] = new Array(); [Code]...
What's happening is, '1000', '1001', '1003', '1004' are being cast as integers, not strings, and it's "filling in" the first ~999 keys as 'undefined' so the length is returning something like 1005, not 7. I'm manually writing the arrays now, and will eventually be building this massive js array from a collection of existing PHP arrays. Is there a way to forcibly cast the values as strings?
Instead I get every char of the string each in one alert message. How can I transform the String to an Array, or get in this case the two key-value pairs?
I have a string array in a class file that contains 5 values, which I need to display on the jsp page. but when I send it to the javascript it prints [Ljava.lang.String;@104f8b8 .what do i do about it. I am a new to javascript. Is there a way to get my array data from the response object.