JavaScript:如何在Asterisk启动Excel数据时终止星号

我正在尝试使用if语句读取excel数据,其中脚本查找任何以Asterisk开头的数据,然后脚本通过终止该字母数字数据中的Asterisk并在Web应用程序的字段中填充该数据,从Excel中读取该数据。

例如以下是我的Excel表格格式:

Data Description Actual Data First Name John Last Name Smith Date Of Birth *02/25/1960 

您可以注意到,在出生date之前我提到了Asterisk,我希望JavaScript只能在脚本识别在出生date之前提到的Asterisk时才能读取。 否则,忽略出生date。

以下代码我使用:

 var $dueDate = person.$dueDate; if ($dueDate == ("*") != -1) { $dueDate = $dueDate.replace(/\*/g,''); var $dueDate = person.$dueDate; person.$dueDate = $dueDate; _log('Due Date is:' + $dueDate); } 

你需要检查*到你的string的外观,请考虑以下简单的例子,

 $(function(){ var strDate = ["*2/11/1983","3/4/1867","4/11/1990"]; $.each(strDate,function(i){ if(strDate[i].indexOf("*") != -1){ strDate[i] = strDate[i].replace(/\*/g,'') // Include this if you need to remove * from string console.log(strDate[i]); } }) }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>