[英]how can i insert "console.log(name[0])" into the variable "var letter"?
var name = 'hammou';
var letter= console.log(name[0]);
現在我想知道第一個字母是不是“H”
if(letter == "h")
{
console.log('your name started by "H"');
}
else
{
console.log('your name does not started by "H"');
}
您不需要使用console.log()
直接使用變量,例如:
var name = 'hammou'; var letter= name[0]; if(letter == "h") { console.log('your name started by "H"'); } else { console.log('your name does not started by "H"'); }
我不確定您要實現什么目標,但您不必記錄代碼即可將其存儲在變量中。 我建議您使用charAt function來獲取字符串的第一個值,並查看變量以獲取有關如何為變量賦值的更多信息。
var name = 'hammou';
var letter= name[0];
if(letter == "h")
{
console.log('your name started by "H"');
}
else
{
console.log('your name does not started by "H"');
}
您不能在變量中插入“console.log(name[0])”,因為“console.log”是在控制台中寫入的,您可以在變量中插入“name[0]”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.