Let's say I have an array var arr = [3,4,5,6,7,9];
and I log the contents like this:
$.each(arr, function(k, v) {
console.log(v);
}
As I log the contents I want to check if the current value is bigger than for example var limit = 5;
.
If the current value is bigger than limit
I want to replace/change that value to let's say the letter A
and print it out as such. So my logged arr
array would look like this 3,4,5,A,A,A
.
I was thinking about something like this:
$.each(arr, function(k,v) {
if (v > limit) {
// set this specific value equal to limit
// log changed value
}
console.log(v); // otherwise just log the value found
});
I tried this, but it does nothing, no errors either.
JSFIDDLE: http://jsfiddle.net/nsgch/8/
var arr = [3,4,5,6,7,9];
var limit = 5;
$.each(arr, function(k,v) {
if (v > limit) {
arr[k] = 'A';
}
console.log( arr[k] );
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With