이 코드를 PHP로 js로 번역했습니다 (정확하게 노드)
$config['test'] = array(
"something" => "http://something.com/web/stats_data2.php"
,"somethingelse" =>"http://somethingelse.com/web/stats_data2.php"
,"anothersomething" =>"http://anothersomething.com/web/stats_data2.php"
);
그래서 저는 이것을 쓰기 시작했습니다.
config.test = [
something = 'http://something.com/web/stats_data2.php'
, somethingelse = 'http://somethingelse.com/web/stats_data2.php'
, anothersomething = 'http://anothersomething.com/web/stats_data2.php']
그러나 대신 다음과 같이 작성하면 안되는지 확실하지 않습니다.
config.test.something = 'http://something.com/web/stats_data2.php';
config.test.something = 'http://somethingelse.com/web/stats_data2.php';
config.test.anothersomething = 'http://anothersomething.com/web/stats_data2.php';
목표는 console.log (config.test. [ 'something']);을 수행하면 출력에 링크가있는 것입니다.
내일 전에 서버가 없기 때문에 서버없이 테스트 할 수있는 방법이 있습니까? 아니면 내 구문이 좋습니까?
Javascript에는 연관 배열이 없으며 일반 객체 만 있습니다.
var myObj = {
myProp: 'test',
mySecondProp: 'tester'
};
alert(myObj['myProp']); // alerts 'test'
myObj.myThirdProp = 'testing'; // still works
for (var i in myObj) {
if (!myObj.hasOwnProperty(i)) continue; // safety!
alert(myObj[i]);
}
// will alert all 3 the props
PHP 배열을 자바 스크립트로 변환하려면 json_encode
그래도 안전하게 플레이하고 싶다면 예약 된 키워드로 인해 일부 브라우저에서 구문이 실패하거나 일부 압축 시스템에서 허용되지 않으므로 속성도 인용하고 싶을 것입니다.
var obj1 = {
function: 'boss', // unsafe
'function': 'employee' // safe
};
console.log(obj1.function); // unsafe
console.log(obj1['function']); // safe
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다