Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I was wondering if it is possible to change the name of a variable from a function paramater
eg.
function(name, content) {
var name = content;
alert(name);
}
No it's not possible. The closest you can get to that is to rename an object property like:
var something = { name: 'me' };
console.log('something', something);
something.content = something.name;
delete something.name;
console.log('something', something);
or as a function:
const rename = (something, oldPropertyName, newPropertyName) => {
something[newPropertyName] = something[oldPropertyName];
delete something[oldPropertyName];
};
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I want to make subfunction like a.b.c(), I can't find name for this. Sorry for english.
What you are describing is just a function within an object, within another object, like so:
const a = {
b: {
c: () => "hello World",
},
};
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
If the input contains a whitespace, add classList 'invalid', otherwise remove it.
function idValidationAttacher() {
const id = document.querySelector('#newid');
id.addEventListener('input', id.classList.toggle('invalid', ));
}
const id = document.getElementById('newid');
id.addEventListener("input", () => {
if(id.value.includes(" ")) {
// Add the code to show the error here.
}
});
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I need to find an element that's text value is 0.
I do:
var d = $('.content').find('div');
if(d.text().length === 0){
//do something
}
Is there a way to put the above logic in the selector?
I've tried:
var d = $('.content').find('div:empty');
But no luck as the div may have other empty html tags in.
Use a filter
var elems = $('.content').find('div').filter(function() { return $(this).text() == 0 });
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need some help. See if you can help me out.
I have a function whose form is:
$this.find(settings.selector).each(function(index) {
Anyway, depending on a variable can change the selector as follows:
$this.each(function(index) {
Can you give me some idea how to do it? I hope I have explained roughly.
Thank you.
You can use a temp variable like
var $els;
if (some_condition) {
$els = $this.find(settings.selector)
} else {
$els = $this;
}
$els.each(function (index) {});
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am having a hard time learning how to iterate through nested arrays, and storing specific array values in javascript.
$('#btn2').click(function(e){
e.preventDefault();
var res = hjs.getValue([1,2,3],['bri', 'alert','name', 'hue', 'sat']);
console.log(res);
});
When #btn2 is clicked on, the following is outputed to my console:
If I'd like to access anyone of these values how would I do so? How do I store the value in a variable?
you can iterate through the object and get the value you want:
$('#btn2').click(function(e){
e.preventDefault();
var res = hjs.getValue([1,2,3],['bri', 'alert','name', 'hue', 'sat']);
for(var i in res)
{
if (res.hasOwnProperty(i)) {
var obj = res[i];
console.log('name: ', obj.name);
console.log('sat: ', obj.sat);
}
}
});